I am implementing background refresh in my app. To test the app I have this in my AppDelegate.m:
-(void)application:(UIApplication *)application
performFetchWithCompletionHandler:
(void (^)(UIBackgroundFetchResult))completionHandler {
NSLog(@"did a background refresh");
completionHandler(UIBackgroundFetchResultNewData);
}
I tested it on the simulator and it works fine. I am unsure of what the use of completionHandler(UIBackgroundFetchResultNewData);
Why do I need to call this and what can I use it for? I understand that it can be:
UIBackgroundFetchResult.NewData - Called when new content has been fetched, and the application has been updated.
UIBackgroundFetchResult.NoData - Called when the fetch for new content went through, but no content is available.
UIBackgroundFetchResult.Failed - Useful for error handling, this is called when the fetch was unable to go through.
However I don't understand why I have to call it and how it's useful. Any pointers on this would be really appreciated. Thanks!
You have to call this to let iOS know what the result of your background fetch was. It uses this information to schedule future background fetches.
If you neglect to do this, future background fetches may be delayed by the OS.
Update: The consequences of not calling this handler might include terminating your app altogether.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With