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

https://developer.apple.com/library/ios/documentation/iphone/reference/uilocalnotification_class/#//apple_ref/occ/instp/uilocalnotification/repeatinterval

for week repeat interval nscalendarunitweekofyear


Comments

Popular posts from this blog

sql - invalid in the select list because it is not contained in either an aggregate function -

Angularjs unit testing - ng-disabled not working when adding text to textarea -

How to start daemon on android by adb -