我正在尝试使用后台提取从 url 获取数据。我的 func 尝试获取数据,如果有新数据,它会发送本地通知。当我最小化应用程序时,大约 10 - 20 分钟后后台提取工作。但是当我终止应用程序(双击主页按钮并关闭应用程序)时它不起作用。我等了大约 1 小时,但没有成功。我在 android 中使用后台服务,它运行成功。有什么方法可以从 url 获取数据并在应用程序关闭时发送本地通知?我正在使用 Xcode 6 和 swift 1.2
最佳答案
用户在多任务 UI 中将其终止后,后台获取将不会在您的应用中发生。这是设计使然。
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/