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:.【iOS推送,两个重要方法】@end
- (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void(^)())completionHandler __IOS_AVAILABLE(10.0) __WATCHOS_AVAILABLE(3.0) __TVOS_PROHIBITED;
当用户通过打开应用程序,解除通知或选择UNNotificationAction来响应通知时,将在代理上调用该方法。 在应用程序从applicationDidFinishLaunching返回之前,必须设置委托。
推荐阅读
- 2020-04-07vue中Axios的封装和API接口的管理
- iOS中的Block
- 刘婵为何不娶关羽的女儿为妻子,而为何要娶张飞的两个女儿
- 说睡
- 记录iOS生成分享图片的一些问题,根据UIView生成固定尺寸的分享图片
- 2019-08-29|2019-08-29 iOS13适配那点事
- Hacking|Hacking with iOS: SwiftUI Edition - SnowSeeker 项目(一)
- iOS面试题--基础
- 有人与我谈格局
- ||11|2019年9月9日