1
votes

Could you please tell me the best practice to use fetchCompletionHandler when receiving the remote notification in the function :


- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult result))completionHandler

I saw people normally write this code at the end of the above function:

completionHandler(UIBackgroundFetchResultNewData);

What if I write :

completionHandler(UIBackgroundFetchResultNoData);

Or what happens even when I don't put the above code?

Note: I am using xcode7.1, objective-c, ios9.1

1

1 Answers

1
votes
  • 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.

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 backgrund fetches may be delayed by the OS.

An example of good use is here.

Update: The consequences of not calling this handler might include terminating your app altogether.