且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如果用户强制退出,iOS 会在后台启动我的应用程序吗?

更新时间:2023-02-19 19:42:39

UPDATE2:

可以使用 iOS 8 中引入的新 PushKit 框架来实现这一点.虽然 PushKit 用于 VoIP.因此,您的使用应与 VoIP 相关,否则存在应用程序拒绝的风险.(请参阅此答案).

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:

文档已针对 iOS8 进行了澄清.可以在此处阅读文档.以下是相关摘录:

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

使用此方法为您的应用处理传入的远程通知.与 application:didReceiveRemoteNotification: 方法不同,后者是仅当您的应用程序在前台运行时调用,系统当您的应用程序在前台运行时调用此方法或背景.此外,如果您启用了远程通知后台模式,系统启动您的应用程序(或从暂停状态)并在推送时将其置于后台状态通知到达.但是系统不会自动如果用户强制退出,则启动您的应用程序.在这种情况下,用户必须在系统之前重新启动您的应用程序或重新启动设备尝试再次自动启动您的应用.

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.

虽然 WWDC 视频没有明确说明这一点,但在开发者论坛上快速搜索发现了这一点:


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(需要登录)

另外请记住,如果您从应用切换器中终止您的应用(即向上滑动以杀死应用程序)然后操作系统将永远不会重新启动应用程序,无论推送通知或后台获取.在这种情况下用户必须手动重新启动应用程序一次,然后从那里重新启动点前进后台活动将被调用.-pmarcos

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

那篇帖子是 Apple 员工写的,所以我想我可以相信这些信息是正确的.

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.