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 

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 日期:2013-12-12主题:【TED】一个关于线结和外科医生的故事 @Ed Gavagan感想:“他们的严格训...
    翱翔GTD阅读 208评论 0 2
  • 今天很乱,随意写点,只是不能间断。 一直想开始晨习,也就是想想而已。 从未开始过晨习,既然下定了决心,每天写点东西...
    一袖风阅读 561评论 0 0
  • 2017.04.02下午昏昏欲睡, 瞅见了篮子里的红薯,想起Q弹的芋圆,于是动手。 首先呢洗干净紫薯 去皮 切成小...
    一只mafan阅读 304评论 0 0
  • 《小狗钱钱》是本挺大名声的书,几次打开电子版都没读下去这次终于打开纸质书,一读就停不下来,里面的很多知识真的是直戳...
    飞飞119阅读 180评论 0 2