Even with "voip" present in "UIBackgroundModes" in "plist", iOS App does not auto start after device reboot in iOS10
Asked Answered
M

2

9

I need my VoIP App to auto start after rebooting the device.

Apple docs clearly mention that :-

(=========EDIT: This is from official Apple docs please have a look at this before commenting or answering that the App cannot be launched without user interaction or silent push notification. Also have a look at Github project below, people have verified this behaviour)

Values for the UIBackgroundModes array

Value : voip Description : The app provides Voice-over-IP services. Apps with this key are automatically launched after system boot so that the app can reestablish VoIP services. Apps with this key are also allowed to play background audio.

https://developer.apple.com/library/content/documentation/General/Reference/InfoPlistKeyReference/Articles/iPhoneOSKeys.html#//apple_ref/doc/uid/TP40009252-SW1

Here is a screenshot from Apple Docs.

I have ensured that :-

  1. The App was running when the device was powered off.
  2. VoIP is present in the plist and Capabilities section.
  3. Ensured that app the certainly not launched after device reboot by adding logs to a file in the main method and the application:didFinishLaunchingWithOptions: method.
  4. Screen of the device is unlocked at least once, after the device has been rebooted.

enter image description here

enter image description here

I even tried executing this GitHub example App with 36 stars to test Boot Launch. https://github.com/lithium3141/BootLaunch
But even this App does not restart on reboot when I tried on device.

Hence, this leads me to think if something has been changed recently in iOS10 or am I still missing something here?

Monmouthshire answered 30/3, 2017 at 7:29 Comment(7)
Without tapping on app icon or receiving push kit payload, your app will never gets revoke automatically. If you want your app is VOIP based and app gets revoke after device reboot. Not possible.Dorotea
@Dorotea I acknowledge your answer as well as your above comment. But I have mentioned an Apple Doc link in the question. Apple states that it can be done. If you would also open the Github link I have given in the question, you would see that Developers have tried and acknowledged that this is possible.Monmouthshire
iOS requires external user interaction event or payload receiving event or else it won't trigger the app execution cycle.Rennold
How have you ensured that your app is not running when the device reboots? Note that looking in the task manager might not be conclusive! I suggest logging, maybe even creating a file for that in the corresponding methods. Another way is to check the process list in Xcode's "Debug - Attach to process..." menu. Also I found this: forums.developer.apple.com/thread/44939, so maybe something in your code just doesn't work when initializing your voip listener? Just an idea for further debugging for now, hope it at least helps a bit. Also: wow at how many people don't get your question...Johannessen
@Johannessen Thank you for the response. Yes, the presence of the app in the multitasking UI is irrelevant in this case. That UI shows a list of recently launched apps and has nothing to do with what apps are running. I had also checked by adding logs to a file. No logs are triggered for the App in the "main" file nor in the "application:didFinishLaunchingWithOptions:" method. This indicates that the App is not launched after Reboot.Monmouthshire
Does the app auto launch if the device has no passcode? That can be important.Gable
@RhythmicFistman Appreciate your response. Even though the device has no passcode, I had ensured that the screen is unlocked after reboot.Monmouthshire
J
6

Okay, I investigated this a bit further, but first I should point out I did not verify this by actually trying to build a project for this as it would be too time consuming for me now.

I found this (already mentioned in the comments), this, and most importantly this tech Q&A.

What I gathered from especially the various comments of the Apple technicians in those threads, it appears that the behavior of iOS 10 has indeed changed. That means that the same code that connected to VoiP servers in past versions of iOS will no longer do that if you link your build against the latest SDK, i.e. iOS 10 libraries.

Now, in your case, you don't actually need a real VoiP connection, right? You are just interested in the "start after reboot" functionality, correct? At least the demo project you linked doesn't actually do any VoiP connection, the setKeepAliveTimeout:handler: method, for example, isn't even implemented. I am aware this specific issue is not discussed in the linked threads or addressed in the Q&A, BUT:

It makes sense that, together with the entire legacy VoiP behavior, the reboot feature vanishes as well. Were you to switch to Push-Kit VoiP, your app wouldn't need to be started after a relaunch, it would restart once the next remote notification arrives (and VoiP notifications have high priority so there's supposedly no delay).

Obviously I am deducting the rationale behind this entire thing here and can't guarantee Apple really thought along those lines, but it makes sense: The entire reason for a (legacy) VoiP app to be (re-)launched after a reboot was that it needed to make a connection, i.e. it needed to run some code. With push notifications that is no longer necessary (the OS basically does that for you behind the scenes to get those notifications), so it makes sense that they removed this functionality along with the entire legacy VoiP approach altogether.

You could test this by compiling against the older SDK (i.e. use Xcode 7 as the Q&A suggests) and see whether it relaunches then. That one apple staffer actually explained that the OS does indeed distinguish on the build SDKs for apps, which is totally counter-intuitive to me. Apparently in this case it would decide "hey, this is an older app, so it expects to be relaunched cause its SDK was documented that way" for apps build on Xcode 7 and "Oh, this app is a new one, so I don't need to stick to the old ways" otherwise. Wowsies.


TL;DR: To me it strongly looks like yes, the iOS SDK changed this behavior along with abandoning the entire old, notification-less VoiP approach. Compiling against the new SDKs will result in apps not being relaunched after reboot.

For the record: I can understand the angry people in those threads. While there might be technical reasons for the change, this specific consequence was far from obvious. If a method is deprecated, but the project still compiles and runs I wouldn't expect such a process to fail in that manner. Those apps don't crash, they're just "treated differently by the OS", which not quite the same. At least I would have expected the documentation to be clearer about this in the new SDK.

Johannessen answered 7/4, 2017 at 7:25 Comment(1)
Thanks. Although I had got a hint from your earlier comment that the behavior might have been discontinued in XCode8/iOS10SDK. This should be verified by compiling against iOS9SDK on XCode7 but the threads make it quiet clear. Also, downgrading from macOS Sierra to ElCapitan for XCode7, just for verifying this behavior, would be lot of effort. Instead, as the framework was already deprecated, its better to move ahead and look for best alternative approaches(Push Kit).Monmouthshire
D
0

App will invoke in background when it is in terminated mode only with push kit silent notification and certificates has to be generate for push kit, not with normal APNS notification and normal push notification certificates.

From back end, your payload has to be like this.

$body['aps'] = array(
'content-available'=> 1,
'alert' => $message,
'sound' => 'default',
'badge' => 0,
);

Once you get pushkit payload, then schedule local notification with sound file, your app will be invoked in background upto your sound file plays.( Max 30 seconds ) Til then you have to complete your background task.

Kindly do refer some important details about push kit integration step by step process

https://github.com/hasyapanchasara/PushKit_SilentPushNotification

Life cycle of app - when app is in terminated and push kit payload comes

  • First of all

    didFinishLaunchingWithOptions // will invoke

  • Then

    didReceiveIncomingPushWithPayload // payload method gets invoke

  • Then if you have local notification

    didReceiveLocalNotification // receive local notification

  • Then

    handleActionWithIdentifier // handler method if you have action buttons ( local )

  • Then if you have remote notification

    didReceiveRemoteNotification // receive remote notification

  • Then

    handleActionWithIdentifier // handler method if you have action buttons ( remote )

Note - Without tapping on app icon or receiving push kit payload, your app will never gets revoke/open/repoen automatically. If you want your app is VOIP based and app gets revoke after device reboot. Not possible.

Dorotea answered 31/3, 2017 at 5:40 Comment(8)
Thank You for your response. I am already aware of the silent APNS approach. But if you refer the Apple Docs link and Github project which I have given in my answer, it is clear that VoIP Apps are/were indeed woken up on reboot, if they were running before the device was rebooted. And that is what I want clarity on.Monmouthshire
Rebooting means, your device will not reboot, when your app is terminated or closed forcefully and pushkit payload arrives then app gets invoke in background with didFinishLaunchingWithOptions ( This is what they mean reboot ).Dorotea
The App is terminated before the device shuts down. But if you check the Apple docs link, VoIP apps should be booted up by the OS on reboot. I am aware of the silent APNS payload approach but I dont intend to use it as it does not suit my requirement.Monmouthshire
You may have referred about this which you said above, but i am sure your app will not get revoked once device reboot while got shut down and app got terminated. Max you can do a 1 thing that keep your VOIP channel details in NSUserDefault and get check on didfinishlaunch and proceed for further call.Dorotea
That is why I have put the link for GitHub project and Apple docs link. If you could have a look, the apple docs clearly state "Value : voip Description : The app provides Voice-over-IP services. Apps with this key are automatically launched after system boot so that the app can reestablish VoIP services"Monmouthshire
Nope, without tapping on app icon and receiving push kit payload, your app will never gets revoke automatically.Dorotea
Let us continue this discussion in chat.Dorotea
@Dorotea Please check the link. It is clear, according to Apple docs that application should be booted up by OS itself.Aeroscope

© 2022 - 2024 — McMap. All rights reserved.