在调用完成处理程序后,每个iOS背景如何处理UIBackgroundFetchResult类型?

应用程序完成后台提取操作后,必须使用三个UIBackgroundFetchResult状态之一调用completionHandler块:UIBackgroundFetchResultNoData,UIBackgroundFetchResultNewData或UIBackgroundFetchResultFailed.

一旦调用完成处理程序,这三个结果中的每一个如何由OS处理?

解决方法

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 16 更新版本时,我们听到了困扰 Apple...
欧版/美版 特别说一下,美版选错了 可能会永久丧失4G,不过只...
一般在接外包的时候, 通常第三方需要安装你的app进行测...
前言为了让更多的人永远记住12月13日,各大厂都在这一天将应...