简体   繁体   English

NSOperation队列在后台不起作用

[英]NSOperation queue not working in background

I want that my image uploading should work in background . 我希望图像上传可以在后台运行 I have enable Background Modes and made a Operation queue to upload multiple files at a time to server. 我启用了“ 后台模式”,并创建了一个“ 操作”队列以一次将多个文件上传到服务器。 But as soon as put app in background NSOperation pauses, and restart again when in foreground. 但是,一旦将应用程序置于后台,NSOperation就会暂停,并在前台运行时再次重新启动。 I have also added beginBackgroundTaskWithExpirationHandler before starting my operation queue and endBackgroundTask when all images get uploaded in server. 我还添加了beginBackgroundTaskWithExpirationHandler以便在将所有图像上传到服务器时启动我的操作队列和endBackgroundTask之前。

This makes all images upload to server also while app is in background, but my app is getting killed, I don't want the app to get killed . 这样一来,当应用程序处于后台状态时,所有图像也都上传到服务器,但是我的应用程序被杀死了,我不希望该应用程序被杀死。

Please suggest some solution to my problem . 请为我的问题提出一些解决方案。

Your app has limited time when running in background. 您的应用在后台运行时的时间有限。 After its allotted time has expired it gets killed. 在分配的时间到期后,它将被杀死。

According to 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.

Also get the value of the backgroundTimeRemaining property to check the remaining time. 还获取backgroundTimeRemaining属性的值以检查剩余时间。

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

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