ios 应用程序中的 APNS

APNS in ios application

能否请您告诉我在函数中接收远程通知时使用 fetchCompletionHandler 的最佳实践:


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

我看到人们通常在上面的函数末尾写这段代码:

completionHandler(UIBackgroundFetchResultNewData);

如果我写:

completionHandler(UIBackgroundFetchResultNoData);

或者即使我不输入上面的代码会发生什么?

注:我用的是xcode7.1, objective-c, ios9.1

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

您必须调用它来让 iOS 知道后台获取的结果是什么。它使用此信息来安排未来的后台提取。

如果您不这样做,以后的后台提取可能会延迟 OS。

一个很好用的例子是here

更新:不调用此处理程序的后果可能包括完全终止您的应用程序。