ios - 在调用完成处理程序后如何处理每个 iOS 后台获取 UIBackgroundFetchResult 类型?

标签 ios objective-c background-process

在您的应用程序在后台获取期间完成其操作后,您必须使用三种 UIBackgroundFetchResult 状态之一调用 completionHandler block :UIBackgroundFetchResultNoDataUIBackgroundFetchResultNewData,或 UIBackgroundFetchResultFailed

调用完成处理程序后,操作系统如何处理这三个结果?

最佳答案

来自iOS App App Programming guide :

When the application:performFetchWithCompletionHandler: method of your delegate is called, use that method to check for new content and to download that content if it is available. When your downloads are complete, execute the provided completion handler block, passing a result that indicates whether content was available. Executing this block tells the system that it can move your app back to the suspended state and evaluate its power usage. Apps that download small amounts of content quickly and accurately reflect when they had content to download are more likely to receive execution time in the future than apps that take longer to download their content

他们没有给我们提供那么多细节,但我认为已经足够清楚了:您将获取的结果传递给系统,因此它可以决定何时给予后台执行时间(以及多少)。
例如,考虑两个不同的应用程序:
- 下载每晚更新的文件
- 其他下载文件更新比较频繁,一天很多次

在这两种情况下,系统都会唤醒您的应用,记下开始时间,您的应用开始下载,然后告诉系统有或没有内容可用。

一段时间后,您会发现系统唤醒第一个应用的频率低于第二个应用,从而优化电池消耗。

此外,如果你使用 NSURLSession 开始下载,系统将评估你的应用程序的功耗(因为使用 NSURLSession 你有“无限”时间下载文件),甚至这个指标用于决定唤醒你的应用程序的频率.

关于ios - 在调用完成处理程序后如何处理每个 iOS 后台获取 UIBackgroundFetchResult 类型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23768971/

相关文章:

python - Capistrano "do nohup python"有效, "do nohup ruby"无效

linux - 如何处理后台 linux 任务的输出

ios - swift 中字典声明的不同方式有哪些

iphone - NSHomeDirectory 删除所有文件

iphone - 在 NSNumberFormatter 中禁用四舍五入(使用语言环境)

objective-c - 求解 objective-c 中的对数

ios - 完成 iOS 后台任务,将其移动到前台

iOS7 : Navigation bar like dropbox

ios - 将 agvtool 与一个目录中的多个 .xcodeproject 文件一起使用

ios - 启用内容插入的 UIScrollView 分页工作异常