ios - 杀死应用程序后后台提取不起作用

标签 ios swift background-process background-fetch

我正在尝试使用后台提取从 url 获取数据。我的 func 尝试获取数据,如果有新数据,它会发送本地通知。当我最小化应用程序时,大约 10 - 20 分钟后后台提取工作。但是当我终止应用程序(双击主页按钮并关闭应用程序)时它不起作用。我等了大约 1 小时,但没有成功。我在 android 中使用后台服务,它运行成功。有什么方法可以从 url 获取数据并在应用程序关闭时发送本地通知?我正在使用 Xcode 6 和 swift 1.2

最佳答案

用户在多任务 UI 中将其终止后,后台获取将不会在您的应用中发生。这是设计使然。

看看Apple's documentation提到:

Apps that support background execution may be relaunched by the system to handle incoming events. If an app is terminated for any reason other than the user force quitting it, the system launches the app...

In most cases, the system does not relaunch apps after they are force quit by the user. One exception is location apps, which in iOS 8 and later are relaunched after being force quit by the user. In other cases, though, the user must launch the app explicitly or reboot the device before the app can be launched automatically into the background by the system.

正如您在文档中注意到的那样,如果应用被强制终止,只有 1 个异常(exception)情况会重新启动:通过使用定位服务。很遗憾,这不适用于您。

此外,您无法检测应用是否被用户强制终止。检查这个StackOverflow answer .

关于ios - 杀死应用程序后后台提取不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35478726/

相关文章:

swift - 快速本地化导航栏标题

ios - 在 Flutter 应用程序中查找 iOS 包标识符

ios - 如何将 UIBarButtonItem 放在 Swift4 上的 NavigationController 的 ViewController 上?

ios - 带有持续时间的 UIView.animate 无法正常工作

ios - 为什么在延迟调用时循环迭代有时会被打乱? [代码和输出]

Azure:结合 Web 和辅助角色:应用程序池回收

ios - Realm - 删除后数据库不是最新的

xcode - 在 swift 中循环零填充数字 - Xcode

android - 如何使用 authToken 发送电子邮件?

ios - 什么是 Xcode "Background Processing"后台模式?