NSOperation队列无法在后台

时间:2015-06-20 14:40:52

标签: ios

我希望图片上传应该在后台运行。 我已启用后台模式,并一次将操作队列上传多个文件发送到服务器。 但是只要把app放在后台NSOperation暂停,并在前台再次重启。 在开始我的操作队列之前,我还添加了 beginBackgroundTaskWithExpirationHandler ,当所有图像都上传到服务器中时,我还添加了 endBackgroundTask

当应用程序处于后台时,这会将所有图像上传到服务器,但我的应用程序被杀死,我不希望该应用程序被杀。

请为我的问题提出一些解决方案。

1 个答案:

答案 0 :(得分:0)

您的应用在后台运行时的时间有限。在分配的时间到期后,它就会被杀死。

根据Apple的说法:

In your own expiration handlers, you can include additional code needed
to close out your task. However, any code you include must not take too 
long to execute because, by the time your expiration handler is called,
your app is already very close to its time limit. For this reason,
perform only minimal cleanup of your state information and end the
task.

还要获取backgroundTimeRemaining属性的值以检查剩余时间。