iOS推送,两个重要方法

@protocol UNUserNotificationCenterDelegate

@optional// 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 options))completionHandler __IOS_AVAILABLE(10.0) __TVOS_AVAILABLE(10.0) __WATCHOS_AVAILABLE(3.0);

只有当应用程序位于前台时,该方法才会在代理上调用。 如果方法未执行或处理程序未及时调用,则不会显示通知。 应用程序可以选择将通知作为声音,徽章,警报或通知列表显示。 该决定应基于通知中的信息对用户是否可见。

// 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 __IOS_AVAILABLE(10.0) __WATCHOS_AVAILABLE(3.0) __TVOS_PROHIBITED;

当用户通过打开应用程序,解除通知或选择UNNotificationAction来响应通知时,将在代理上调用该方法。 在应用程序从applicationDidFinishLaunching返回之前,必须设置委托。

@end 

你可能感兴趣的:(iOS推送,两个重要方法)