ios - How to set NSLocalNotification to run on monthly or weekly basis for the same time scheduled? -
i have app data coming server. have 2 type of notifications monthly.now data month (date-time format) 2-2:30,6-9:00,23-10:00,26-12:00. 2 denotes date followed time colon (:) format.
now want run notification every month on same dates , time. able run multiple notifications. not repeat every month. how that. following code same. please missing.
- (bool)application:(uiapplication *)application didfinishlaunchingwithoptions:(nsdictionary *)launchoptions { [uiapplication sharedapplication].idletimerdisabled = yes; uiusernotificationsettings *notisett = [uiusernotificationsettings settingsfortypes:uiusernotificationtypebadge | uiusernotificationtypealert | uiusernotificationtypesound categories:null]; [[uiapplication sharedapplication]registerusernotificationsettings:notisett]; [self generatelocalnotificationdaily]; } -(void)generatelocalnotificationdaily { // [[uiapplication sharedapplication] cancelalllocalnotifications]; [self comparedatedaily]; } -(void)comparedatedaily { nsstring *strtime = [helper getpref:pref_alarm_daily_time]; nsarray *arrtime = [strtime componentsseparatedbystring:@","]; for(int i=0;i<[arrtime count];i++) { nsarray *arrfirsttime = [[nsstring stringwithformat:@"%@",[arrtime objectatindex:i]]componentsseparatedbystring:@":"]; int hh = (int)[[arrfirsttime objectatindex:0]integervalue]; int mm = (int)[[arrfirsttime objectatindex:1]integervalue]; nsdate *now = [nsdate date]; nstimeinterval secondsperday = 1;//24 * 60 * 60; nsdate *date = [now datebyaddingtimeinterval:secondsperday]; nscalendar *calendar = [[nscalendar alloc] initwithcalendaridentifier: nscalendaridentifiergregorian]; nsdatecomponents *components = [calendar components:nscalendarunityear|nscalendarunitmonth|nscalendarunitday fromdate:date]; [components sethour:hh]; [components setminute:mm]; nsdate *todayspecificdate = [calendar datefromcomponents:components]; nsdateformatter *formatter = [[nsdateformatter alloc] init]; [formatter setdateformat:@"yyyy-mm-dd hh:mm:ss"]; [formatter settimezone:[nstimezone systemtimezone]]; nsdate *currentdate = [nsdate date]; nsstring *strcurrentdate = [formatter stringfromdate:currentdate]; nsstring *strsystemdate = [formatter stringfromdate:todayspecificdate]; currentdate = [formatter datefromstring:strcurrentdate]; todayspecificdate = [formatter datefromstring:strsystemdate]; nscomparisonresult result = [currentdate compare:todayspecificdate]; nsstring *stralertmessage = [nsstring stringwithformat:@"%@",[helper getpref:pref_alarm_message]]; nsstring *strusername = [helper getpref:pref_name]; nsstring *strmsg = [stralertmessage stringbyreplacingoccurrencesofstring:@"user_name" withstring:strusername]; nsstring *alertmsg = [strmsg stringbyreplacingoccurrencesofstring:@"notification_type" withstring:@"daily"]; // switch (result) { case nsorderedascending: { uilocalnotification* localnotificationdaily = [[uilocalnotification alloc] init]; localnotificationdaily.firedate = todayspecificdate; localnotificationdaily.alertbody = alertmsg; localnotificationdaily.repeatinterval = nscalendarunitday; localnotificationdaily.soundname = uilocalnotificationdefaultsoundname; [[uiapplication sharedapplication] schedulelocalnotification:localnotificationdaily]; nslog(@"%@ in future %@", todayspecificdate, currentdate); } break; case nsordereddescending: nslog(@"%@ in past %@", todayspecificdate, currentdate); break; case nsorderedsame: nslog(@"%@ same %@", todayspecificdate, currentdate); break; default: nslog(@"erorr dates %@, %@", todayspecificdate, currentdate); break; } } }
there property in uilocalnotification "repeatinterval". have set repeat interval month this
localnotificationmonthly.repeatinterval = nscalendarunitmonth;
it repeat notification every month depending upon date , time set notification. further inquiry please refer
for week repeat interval nscalendarunitweekofyear
Comments
Post a Comment