Reputation: 11
I have a date picker called timePicker that allows the user to select hour and minutes to receive the notification, and on button click I want to schedule notification at that time for the current day if the time has not yet passed, or for the next day if the time has passed. I then want the notification to repeat every day at the exact same time. I have the first part kind of figured out, but I can't get the repeating to work. The code is legacy, and as such is written in objective c. I would greatly appreciate as much of a code example as you are willing to write for me, but any advice at all would be greatly appreciated. Thank you!!
Upvotes: 0
Views: 111
Reputation: 17902
Something like this is what you are likely looking for.
UILocalNotification *notification = [UILocalNotification new];
notification.fireDate = /*Alert Date*/;
notification.repeatInterval = NSCalendarUnitDay;//Once per day
[notification setAlertBody:@"Your message"];
[[UIApplication sharedApplication] scheduleLocalNotification:notification];
Set the repeatInterval to whatever NSCalendarUnit you'd like.
If you need something more custom just make an iterative loop and change the fireDate accordingly each iteration. (Make sure you unschedule them in the next session if needed).
Upvotes: 0