UILocalNotification when disconnecting iPhone

What happens when UILocalNotofication is assigned when the device is turned off.

Eg. I plan on UILocalNotification at 15:00 every day. But the device is turned off from 15:00 to 16:00. I assume that one of the following conditions will be met.

  • After restarting the device, the notification does not start.
  • The notification is triggered when the device restarts, i.e. at 16:00.

I do not have a device and I can not check it on the simulator.

Note. By disconnecting, I mean that the device is turned off, not sleep / standby

+3
source share
2 answers

When you turn off your device, the notification becomes non-existent, so when you turn on the device again, nothing will happen without generating this notification again.

So, if you are planning an event for 3PM, and your device is turned off at 2:59 p.m., and then at 15:59 p.m., the notification will not be triggered, because it must be recreated.

0
source

Local notifications will be activated after turning your device on and off.

I wrote a small test application that tests this behavior:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { [[UIApplication sharedApplication] cancelAllLocalNotifications]; NSDate *nowDate = NSDate.date; for (int i = 1; i <= 50; i++) { UILocalNotification *n = [[UILocalNotification alloc]init]; n.fireDate = [nowDate dateByAddingTimeInterval:60 * i ]; n.applicationIconBadgeNumber = 0; n.alertAction = @"Open"; n.alertBody = [NSString stringWithFormat:@"ln %@ %@", @(i), n.fireDate]; [[UIApplication sharedApplication] scheduleLocalNotification:n]; } return YES; } 
+4
source

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


All Articles