Apple允许后台任务运行多长时间? [英] How long does Apple permit a background task to run?
问题描述
我必须将一组图像文件上传到数据库,因此,我偶然发现了 Apple的后台执行指南,以确保在用户暂停或终止我的应用时应用仍会上传数据。
I have to upload an array of image files to database, therefore, I stumbled upon Apple's background execution guide to make sure the app still uploads the data when user suspends or terminates my app.
但是在解释中,如果我们调用 beginBackgroundTaskWithName:expirationHandler:
,则说给它一点额外的时间来完成它的工作
beginBackgroundTaskWithExpirationHandler:
开始后台任务。
But in the desciption, it says giving it a little extra time to finish its work
if we call beginBackgroundTaskWithName:expirationHandler:
or beginBackgroundTaskWithExpirationHandler:
to start a background task.
多长时间正是吗?
推荐答案
如果我错了,请纠正我,但我偶然发现了。
Correct me if I am wrong, but I have stumbled upon a perfect article from Xamarin that discusses iOS backgrounding feature.
我将简单分为两部分,ios pre 7和ios 7+:
I will simply break down to two parts, ios pre 7 and ios 7+:
答案只是
600
秒(10分钟),原因由上面的文章
提供。
The answer is simply
600
seconds (10 minutes), reason is provided by the article above.
iOS版本7 +
iOS version 7+
答案是时间系统分配给你的是机会主义。你
必须使用@Gary Riches的建议
The answer is that the time system allocates you is opportunistic. You will have to use @Gary Riches's suggestion
NSLog(@"Time Remaining: %f", [[UIApplication sharedApplication] backgroundTimeRemaining]);
查找。机会主义的原因是iOS 7+
处理后台任务的方式完全不同,当然是优化的。确切地说是
,它有间歇性的行为,因此,如果你需要
后台任务,比如下载一大堆数据,如果你使用<$,那么
会更有效c $ c> NSURLSession 而不是。
to find out. The reason for it being opportunistic is the way iOS 7+
handles background tasks is completely different, certainly optimised. To
be exact, It has an intermittent behaviour, and therefore, if you need
background tasks such as downloading a big chuck of data, it will be
much more effective if you use NSURLSession
instead.
但是,在我的特殊情况下,我上传了一个单一的对象包含一个文件准确。我不必考虑上传少量数据的 NSURLSession
。此外,它是上传任务,它可能需要花费尽可能多的时间。 : - )
However, in my special case, I am uploading one single object that contains one file to be exact. I do not have to consider NSURLSession
for uploading a small amount of data. And besides, it's uploading task, it can take as much time as it wants. :-)
对于这些 TL; DR
访问者,上面的答案应该足够了。有关详细信息,请参阅上面的文章。
For these TL;DR
visitors, the answer above should be sufficient. For more details, please refer to the article above.
这篇关于Apple允许后台任务运行多长时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!