I've currently got local notifications set so that users can select a time on the datePicker (hour, minute, and am/pm) when they would like notifications sent. It works fine... up until the next day. It seems that the notification only works on the same day, and resets once midnight hits. How do I prevent the alarm from resetting, so that a notification is sent daily?
Here's my code so far:
(IBAction)scheduleNotification:(id)sender {
UILocalNotification *notification = [[UILocalNotification alloc]init];
NSDate *fireDate = _datePicker.date;
[notification setFireDate:fireDate];
[notification setAlertBody:@"Daily Reminder"];
[notification setAlertAction:@"Go to app"];
[[UIApplication sharedApplication]scheduleLocalNotification:notification];
//Local push notifications
}
(IBAction)didChangeDatePicker:(id)sender {
NSLog(@"New reminder time selected: %@",self.datePicker.date);
}
You need to add:
[notification setRepeatInterval:NSDayCalendarUnit];
It will then recur every day until you cancel it with:
[[UIApplication sharedApplication] cancelLocalNotification:notification];
or
[[UIApplication sharedApplication] cancelAllLocalNotifications];
which by the way only cancels notifications set by your app.
Too, this is well-presented in the documentation if you search on UILocalNotification
.