Even with “voip” present in “UIBackgroundModes” in “plist”, iOS App does not auto start after device reboot in iOS10

橙三吉。 提交于 2019-12-30 03:13:49

问题


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

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.

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?


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/43111249/even-with-voip-present-in-uibackgroundmodes-in-plist-ios-app-does-not-aut

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!