Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Having issue with repeatinterval every 30 minutes

I am trying to repeat a local notification every 30 minutes but my code does not work fine ... I would be grateful if you help me and find the solution , here is my code :

UILocalNotification *reminderNote = [[UILocalNotification alloc]init];
reminderNote.fireDate = [NSDate dateWithTimeIntervalSinceNow:60 * 30];
reminderNote.repeatInterval = NSHourCalendarUnit;
reminderNote.alertBody = @"some text";
reminderNote.alertAction = @"View";
reminderNote.soundName = @"sound.aif";
[[UIApplication sharedApplication] scheduleLocalNotification:reminderNote];
like image 787
iOS.Lover Avatar asked Feb 06 '12 15:02

iOS.Lover


1 Answers

firedate sets the time that the notification fires the first time, and repeatInterval is the interval between between repetitions of the notification. So the code in the question schedules a notification to fire 30 minutes (60 * 30 seconds) from now, and then repeat every hour.

Unfortunately, you can only schedule notifications to repeat at exact intervals defined by NSCalendar constants: e.g., every minute, every hour, every day, every month, but not at multiples of those intervals.

Luckily, to get a notification every 30 minutes, you can just schedule two notifications: one right now, one 30 minutes from now, and have both repeat every hour. Like so:

UILocalNotification *reminderNote = [[UILocalNotification alloc]init];
reminderNote.fireDate = [NSDate dateWithTimeIntervalSinceNow:60 * 30];
reminderNote.repeatInterval = NSHourCalendarUnit;
reminderNote.alertBody = @"some text";
reminderNote.alertAction = @"View";
reminderNote.soundName = @"sound.aif";
[[UIApplication sharedApplication] scheduleLocalNotification:reminderNote];

reminderNote.fireDate = [NSDate dateWithTimeIntervalSinceNow:60 * 60];
[[UIApplication sharedApplication] scheduleLocalNotification:reminderNote];
like image 67
yuji Avatar answered Sep 22 '22 14:09

yuji