I have an iOS7 app which registers for background mode remote-notification:
<key>UIBackgroundModes</key>
<array>
<string>remote-notification</string>
</array>
It works fine before reboot and app gets this event while in background:
-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
But it looks like after reboot I don't get this event anymore until I start application manually.
So, question is: can I make iOS7 to run my app into background after reboot when it receives silent push notification for my app? My push notifications don't have "alert" field, only "contentAvailable" - can this be a reason? I've seen apps like whatsapp being able to receive and show push notifications immediately after reboot so it looks doable for at least "alert" kind of notifications.
I know that I can use significant location monitoring to restart app at some point after reboot but I would like to avoid showing location icon on toolbar all the time. Can background-fetch mode help with that? Is there any statistics, how fast after reboot app with background fetch mode will be executed?
Apple does not offer a way to handle a notification that arrives when your app is closed (i.e. when the user has fully quit the application or the OS had decided to kill it while it is in the background). If this happens, the only way to handle the notification is to wait until it is opened by the user.
iOS puts strict limits on background execution. Its default behaviour is to suspend your app shortly after the user has moved it to the background; this suspension prevents the process from running any code. There's no general-purpose mechanism for: Running code continuously in the background.
Notification messages delivered when your app is in the background. In this case, the notification is delivered to the device's system tray. A user tap on a notification opens the app launcher by default. Messages with both notification and data payload, when received in the background.
Overview. Use remote notifications (also known as push notifications) to push small amounts of data to devices that use your app, even when your app isn't running. Apps use notifications to provide important information to users. For example, a messaging service sends remote notifications when new messages arrive.
No, It won't work. Because your app will be in Not Running state as you rebooted your device.
As per apple doc, the new multitasking API(fetch and remote-notification) will work only when the app in the suspended/background/foreground state. If the app is in background/foreground state, then application:didReceiveRemoteNotification:fetchCompletionHandler
will get triggered. If the app is in suspended state, then -(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
will get triggered.
In your case the app is in Not Running state, because of that application:didReceiveRemoteNotification:fetchCompletionHandler
is never get triggered.
Please refer apple doc for more about app states.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With