Interval release every 30 minutes

I try to repeat the local notification every 30 minutes, but my code is not working fine ... I would appreciate if you could help me and find a 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]; 
+6
source share
1 answer

firedate sets the time during which the notification is triggered for the first time, and repeatInterval is the interval between repetitions of the notification. Thus, the code in the question provides a notification of 30 minutes (60 * 30 seconds), and then repeats every hour.

Unfortunately, you can only schedule notifications for repeating at exact intervals determined by NSCalendar constants : for example, every minute, every hour, every day, every month, but not in a multiple of these intervals.

Fortunately, to receive a notification every 30 minutes, you can simply schedule two notifications: one right now, after 30 minutes, and repeat every hour every time. For instance:

 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]; 
+13
source

Source: https://habr.com/ru/post/907778/


All Articles