Does iOS start app in background after reboot if remote-notification defined in UIBackgroundModes and new push notification comes?
Asked Answered
I

1

6

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?

Insurrection answered 19/12, 2013 at 13:23 Comment(0)
H
10

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.

Heald answered 20/12, 2013 at 5:45 Comment(6)
I see this behaviour in my tests. But question was "can I make iOS7 to run my app into background after reboot when it receives silent push notification for my app?". So, is there any way to start again getting remote notifications after reboot so that user does not need to launch app manually?Insurrection
There is no way to start the app in background after rebooting the device. User needs to open the app at least once after reboot. Then only remote notification will work.Heald
I've accepted this as an answer. We decided to add visual notification in case if user is not reporting for long time - it allows to remind user to restart app after device reboot.Insurrection
Your reason .."because your app will be in not runnin state" is wrongful. It all depends on the combination of a) Background Fetching (in your app's code configuration settings), and b) relying on the fact the end-user did not disable "Background App Refresh" from the Settings -> General -> background App Refresh. If both are implemented, the app will be brought to SUSPENDED MODE or BACKGROUND STATE from a NOT RUNNING state, depending on your update type of choice (e.g. Location, VOIP, Audio, etc.)Kirsti
Thanks Nandha! Is there anyway to get in touch with you? :-)Loosetongued
Hi, I want to get notification when app is terminated and if app is not running then again I want notification every 72 hours. How can I achieve this ? Is it possible with local notification? Also, I am getting issue with local notification - I restart the device. I don't force-quit the app. And now the notifications don't trigger anymore. I need to open the app again. What can I do?Panatella

© 2022 - 2024 — McMap. All rights reserved.