iOS 中 didReceiveRemoteNotification 的两个委托方法有什么区别?

IKK*_*KKA 5 objective-c push-notification ios

我已经Push Notification在我的iOS应用程序中实现了。我可以看到两种delegate方法didReceiveRemoteNotification,如下所示:这两种方法有什么区别?

\n\n
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo { }\n
Run Code Online (Sandbox Code Playgroud)\n\n

\n\n
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo\n\xc2\xa0 \xc2\xa0 fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {\n\xc2\xa0 completionHandler(UIBackgroundFetchResultNewData);\n}\n
Run Code Online (Sandbox Code Playgroud)\n

abd*_*lek 3

第一个在 iOS 10.0 中已弃用,请使用第二个。第二个的信息

即使应用程序因远程通知而启动或恢复,也会调用此方法。将首先调用相应的委托方法。请注意,此行为与 application:didReceiveRemoteNotification: 相反,在这些情况下不会调用 application:didReceiveRemoteNotification:,并且如果实现此方法,则不会调用 application:didReceiveRemoteNotification:。

对于第一个

使用 UserNotifications Framework 的 -[UNUserNotificationCenterDelegate willPresentNotification:withCompletionHandler:] 或 -[UNUserNotificationCenterDelegate didReceiveNotificationResponse:withCompletionHandler:] 用于用户可见通知,使用 -[UIApplicationDelegate application:didReceiveRemoteNotification:fetchCompletionHandler:] 用于静默远程通知