How to create a UILocalNotification that notifies every two minutes

So I'm basically trying to install an application that constantly reports local notifications.

So far, I:

- (void)scheduleNotification { [reminderText resignFirstResponder]; [[UIApplication sharedApplication] cancelAllLocalNotifications]; Class cls = NSClassFromString(@"UILocalNotification"); if (cls != nil) { UILocalNotification *notif = [[cls alloc] init]; notif.fireDate = [datePicker date]; notif.timeZone = [NSTimeZone defaultTimeZone]; notif.alertBody = @"Your building is ready!"; notif.alertAction = @"View"; notif.soundName = UILocalNotificationDefaultSoundName; notif.applicationIconBadgeNumber = 1; NSInteger index = [scheduleControl selectedSegmentIndex]; switch (index) { case 1: notif.repeatInterval = NSMinuteCalendarUnit; break; case 2: notif.repeatInterval = NSMinuteCalendarUnit*2; break; default: notif.repeatInterval = 0; break; } NSDictionary *userDict = [NSDictionary dictionaryWithObject:reminderText.text forKey:kRemindMeNotificationDataKey]; notif.userInfo = userDict; [[UIApplication sharedApplication] scheduleLocalNotification:notif]; [notif release]; } } 

I try to do this to get notified every 2 minutes (when I set case 2) and every 1 minute (when I set case 1) to get a notification. The only problem is that ... * 2 does not work to be notified every 2 minutes. How can I make it notify every 2 minutes?

+6
source share
1 answer

You can only use specific calendar units in NSCalendarUnit when you set the repeatInterval property to UILocalNotification. You cannot use user devices or manipulate devices, so you cannot do what you want using the notification interval repetition property.

To schedule notifications every 2 minutes, you will most likely want to schedule multiple notifications at different times (2 minutes apart). You can create a UILocalNotification and then schedule it with:

 [[UIApplication sharedApplication] scheduleLocalNotification: localNotification]; 

then change the fireDate property (by adding a snooze interval) and then schedule it again using the same code. You can repeat this in a loop, but many times you need to repeat the notification.

+2
source

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


All Articles