I am trying to fire an uilocalnotification for every 15 with repeated intervals at 6 AM in the morning.
i have tried a sample code, but not sure how to test it in simulator.
NSDate *now = [NSDate date];
NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
NSDateComponents *components = [calendar components:NSCalendarUnitYear|NSCalendarUnitMonth|NSCalendarUnitDay fromDate:now];
[components setHour:6];
[components setMinute:0];
[components setSecond:0];
// Gives us today's date but at 6am
NSDate *next6am = [calendar dateFromComponents:components];
NSLog(@"next9am BEFORE :%@",next6am);
if ([next6am timeIntervalSinceNow] < 0) {
// If today's 6am already occurred, add 24hours to get to tomorrow's
next6am = [next6am dateByAddingTimeInterval:60*60*24*15];
}
UILocalNotification* Localnotification = [[UILocalNotification alloc]init];
Localnotification.fireDate = next6am;
Localnotification.alertBody = @“it is been 15 days“;
Localnotification.repeatInterval = NSCalendarUnitWeekOfYear*2+NSCalendarUnitDay;
[[UIApplication sharedApplication] scheduleLocalNotification:Localnotification];
but not sure how to test it in simulator and not sure it will work help will be appreciated.
Thanks
After lot of searching over the internet and trying work around , i came to know that iOS repeat interval are as follows,
We can set the repeat interval in the above fashion only.
But if we want to repeat interval for every 15 days we need to write an custom repeat interval for UILocalNotification .
so every year has 12 months and the number of event to be scheduled is 24 so i made loop for 2 years(730 days) and scheduled 48 event for the next 2 years
the below is the code for achieving the result
You can see all the scheduled events with this below method
Hope this could help some one who are looking for a solution :)