How are each of the iOS background fetch UIBackgroundFetchResult types handled after the completion handler is called? How are each of the iOS background fetch UIBackgroundFetchResult types handled after the completion handler is called? ios ios

How are each of the iOS background fetch UIBackgroundFetchResult types handled after the completion handler is called?


From the 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

They don't give us so many details, but I think is clear enough: you pass the result of the fetch to the System, so it can decide when to give background execution time (and how much).
Example, consider two different apps:
- one downloads files that are updated every night
- the other downloads files that are updated more frequently, many times in a day

In both cases, the system will wake up your app, takes note of the start time, your app starts the download and then tells the system that there was or not content available.

After some time, you'll see that the system will wake up the first app less frequently than the second one, optimizing battery consumption.

Moreover, if you use NSURLSession to start you download, the system will evaluate your app's power consumption (since using NSURLSession you have "unlimited" time to download files), even this metric is used to decide how often wake up your app.