Reputation: 341
I cannot seem to find an explicit thread that answers these questions:
"Does a scheduled UILocalNotification fire when app is not running (i.e. is not in the foreground or background)"?
"Do UILocalNotifications fire when the app is not running (i.e. is not in the foreground or background) and the phone is in lock/sleep mode?"
Some answers suggest that they will, as UILocalNotifications are handled by the iOS operating system. Some seem to imply that they will only fire if the app is running in the background or foreground. I cannot find much about whether UILocalNotifications work if the phone is locked.
Thanks, James
Upvotes: 2
Views: 2375
Reputation: 42977
Simply YES
From apple docs
When the system delivers a local notification, several things can happen, depending on the application state and the type of notification. If the application is not frontmost and visible, the system displays the alert message, badges the application, and plays a sound—whatever is specified in the notification. If the notification is an alert and the user taps the action button (or, if the device is locked, drags open the action slider), the application is launched.`
UILocalNotification is handled by the OS. Once you schedule it, os will manage it for you. Whether the application is running or not system will give notification. You only need to respond to it in application:didReceiveLocalNotification: and application:didFinishLaunchingWithOptions: (to handle if the application is launched due to notification)
remember
If the application is foremost and visible when the system delivers the notification, no alert is shown, no icon is badged, and no sound is played. However, the application:didReceiveLocalNotification: is called if the application delegate implements it.
Upvotes: 6
Reputation: 1752
Yes. Local notification will fire whether your app is running in background or foreground.
If your app running in foreground then
- (void)application:(UIApplication*)application didReceiveLocalNotification:(UILocalNotification*)notification
will call.
If your phone is Lock then also UILocalNotification will works but it will show without alert body.(i.e Alert without Button).
Upvotes: 0
Reputation: 2703
Yes:
The operating system is responsible for delivering the notification at the proper time; the application does not have to be running for this to happen.
Upvotes: 1