Push notification 如何在iOS 10中接收后台通知?

Push notification 如何在iOS 10中接收后台通知?,push-notification,ios10,firebase-notifications,Push Notification,Ios10,Firebase Notifications,描述-正常运行iOS 9,调用以下方法 - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler 但从iOS 10开始,苹果提供了新的框架,即userNotification.framework 以

描述-正常运行iOS 9,调用以下方法

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
但从iOS 10开始,苹果提供了新的框架,即userNotification.framework 以及新的处理方法,即

// The method will be called on the delegate only if the application is in the foreground. If the method is not implemented or the handler is not called in a timely manner then the notification will not be presented. The application can choose to have the notification presented as a sound, badge, alert and/or in the notification list. This decision should be based on whether the information in the notification is otherwise visible to the user.

- (void)userNotificationCenter:(UNUserNotificationCenter *)center
       willPresentNotification:(UNNotification *)notification
         withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler

但现在,当应用程序处于后台且用户未单击通知时,我无法收到通知回拨

我想要的是,当用户在后台时,如果他收到任何通知,那么我将使用哪种方法获得收到的通知的回调


提前感谢。

在iOS10中,当应用程序运行前台时,将调用willPresentdidReceive将在应用程序运行后台时,当用户点击通知时调用

如果您想在应用程序运行后台时处理通知,您仍然需要实现DidReceiveMemotentification…fetchCompletionHandler,并且不要忘记将“内容可用”添加到通知负载中。将其设置为1

// The method will be called on the delegate when the user responded to the notification by opening the application, dismissing the notification or choosing a UNNotificationAction. The delegate must be set before the application returns from applicationDidFinishLaunching:.

- (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)())completionHandler