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

Background fetch is not working after killing the app

我正在尝试通过后台提取从 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 个例外:通过使用定位服务。很遗憾,这不适用于您。

此外,您无法检测应用是否被用户强行杀死。检查这个 Whosebug answer.

用户从后台终止应用程序后,后台获取不会在您的应用程序中更新。不可能