Will iOS launch my app into the background if it was force-quit by the user?

后端 未结 7 780
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-22 00:46

I am triggering a background fetch by using the content-available flag on a push notification. I have the fetch and remote-notification

相关标签:
7条回答
  • 2020-11-22 01:13

    You can change your target's launch settings in "Manage Scheme" to Wait for <app>.app to be launched manually, which allows you debug by setting a breakpoint in application: didReceiveRemoteNotification: fetchCompletionHandler: and sending the push notification to trigger the background launch.

    I'm not sure it'll solve the issue, but it may assist you with debugging for now.

    screenshot

    0 讨论(0)
  • 2020-11-22 01:17

    Actually if you need to test background fetch you need to enable one option in scheme:

    enabling bg fetch

    Another way how you can test it: simulate bg fetch

    Here is full information about this new feature: http://www.objc.io/issue-5/multitasking.html

    0 讨论(0)
  • 2020-11-22 01:20

    UPDATE2:

    You can achieve this using the new PushKit framework, introduced in iOS 8. Though PushKit is used for VoIP. So your usage should be for VoIP related otherwise there is risk of app rejection. (See this answer).


    UDPDATE1:

    The documentation has been clarified for iOS8. The documentation can be read here. Here is a relevant excerpt:

    Use this method to process incoming remote notifications for your app. Unlike the application:didReceiveRemoteNotification: method, which is called only when your app is running in the foreground, the system calls this method when your app is running in the foreground or background. In addition, if you enabled the remote notifications background mode, the system launches your app (or wakes it from the suspended state) and puts it in the background state when a push notification arrives. However, the system does not automatically launch your app if the user has force-quit it. In that situation, the user must relaunch your app or restart the device before the system attempts to launch your app automatically again.


    Although this was not made clear by the WWDC video, a quick search on the developer forums turned this up:

    https://devforums.apple.com/message/873265#873265 (login required)

    Also keep in mind that if you kill your app from the app switcher (i.e. swiping up to kill the app) then the OS will never relaunch the app regardless of push notification or background fetch. In this case the user has to manually relaunch the app once and then from that point forward the background activities will be invoked. -pmarcos

    That post was by an Apple employee so I think i can trust that this information is correct.

    So it looks like when the app is killed from the app switcher (by swiping up), the app will never be launched, even for scheduled background fetches.

    0 讨论(0)
  • 2020-11-22 01:23

    The answer is YES, but shouldn't use 'Background Fetch' or 'Remote notification'. PushKit is the answer you desire.

    In summary, PushKit, the new framework in ios 8, is the new push notification mechanism which can silently launch your app into the background with no visual alert prompt even your app was killed by swiping out from app switcher, amazingly you even cannot see it from app switcher.

    PushKit reference from Apple:

    The PushKit framework provides the classes for your iOS apps to receive pushes from remote servers. Pushes can be of one of two types: standard and VoIP. Standard pushes can deliver notifications just as in previous versions of iOS. VoIP pushes provide additional functionality on top of the standard push that is needed to VoIP apps to perform on-demand processing of the push before displaying a notification to the user.

    To deploy this new feature, please refer to this tutorial: https://zeropush.com/guide/guide-to-pushkit-and-voip - I've tested it on my device and it works as expected.

    0 讨论(0)
  • 2020-11-22 01:24

    For iOS13

    For background pushes in iOS13, you must set below parameters:

    apns-priority = 5
    apns-push-type = background
    //Required for WatchOS
    //Highly recommended for Other platforms 
    

    The video link: https://developer.apple.com/videos/play/wwdc2019/707/

    0 讨论(0)
  • 2020-11-22 01:26

    I've been trying different variants of this for days, and I thought for a day I had it re-launching the app in the background, even when the user swiped to kill, but no I can't replicate that behavior.

    It's unfortunate that the behavior is quite different than before. On iOS 6, if you killed the app from the jiggling icons, it would still get re-awoken on SLC triggers. Now, if you kill by swiping, that doesn't happen.

    It's a different behavior, and the user, who would continue to get useful information from our app if they had killed it on iOS 6, now will not.

    We need to nudge our users to re-open the app now if they have swiped to kill it and are still expecting some of the notification behavior that we used to give them. I'm worried this won't be obvious to users when they swipe an app away. They may, after all, be basically cleaning up or wanting to rearrange the apps that are shown minimized.

    0 讨论(0)
提交回复
热议问题