3

What happens when a UILocalNotofication is scheduled when a device is switched off.

Eg. I schedule a UILocalNotification at 3pm everyday. But the device is switched off from 3:00pm to 4:00pm. I guess any one of the following conditions will be true.

  • No notification is fired after device is restarted.
  • Notification is fired when the device is restarted i.e. at 4:00pm

I do not have a device and could not test it on a simulator.

Note: By switch off I mean that the device is turned off, and not sleep/stand by mode

Sahil Khanna
  • 4,262
  • 8
  • 47
  • 72

2 Answers2

4

Local Notifications will be triggered after turning your device off and on.

I wrote a tiny test app, that verifies this behaviour:

- (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;
}
Klaas
  • 22,394
  • 11
  • 96
  • 107
-3

When you turn off your device, the notification becomes non-existant, so when you turn your device back on, nothing is going to happen without creating that notification again.

So if you schedule an event for 3PM and your device is turned off at 2:59PM, then back on at 3:59PM, the notification will not fire because it has to be recreated.

WrightsCS
  • 50,551
  • 22
  • 134
  • 186
  • 4
    That's not correct. A local notification does persist a reboot, it is not lost unless its fire time was while the device was switched off. – Dev Feb 17 '12 at 07:44
  • so, what's the verdict on this? does anyone have any citations to support either theories? – Cashew Jan 08 '13 at 05:52
  • Hi, one simple ques? Suppose, I have set notification for tomorrow at 11 AM. Then close the app. And go to setting date-time, and changed tomorrow and time 10:55 AM. So, after 5 min, can I get notification or not? Currently I am not getting any notification. Can you please help? and share your idea. Many Thanks. – Nishant B Mar 06 '13 at 09:55
  • 1
    This answer is incorrect, I tested and notifications persist during reboot – aryaxt Mar 24 '15 at 23:22
  • If you read the answer, in this case, the notification fired when the device was OFF, so this is the correct behavior. – WrightsCS Mar 25 '15 at 15:57