繁体   English   中英

NSOperation队列在后台不起作用

[英]NSOperation queue not working in background

我希望图像上传可以在后台运行 我启用了“ 后台模式”,并创建了一个“ 操作”队列以一次将多个文件上传到服务器。 但是,一旦将应用程序置于后台,NSOperation就会暂停,并在前台运行时再次重新启动。 我还添加了beginBackgroundTaskWithExpirationHandler以便在将所有图像上传到服务器时启动我的操作队列和endBackgroundTask之前。

这样一来,当应用程序处于后台状态时,所有图像也都上传到服务器,但是我的应用程序被杀死了,我不希望该应用程序被杀死。

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

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

根据苹果的说法:

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属性的值以检查剩余时间。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM