iOS开发中App在杀死状态下点击推送获取推送内容

在didFinishLaunchingWithOptions方法中又一个参数:launchOptions,我们可以从该字段中获取到推送消息。launchOptions是一个字典,其做为推送消息的载体,其格式以及内容和推送消息中的userInfo一样。

App杀死状态下点击推送消息栏

  if (launchOptions) { //是否有推送消息
  NSDictionary *remoteNotification = [launchOptions objectForKey: UIApplicationLaunchOptionsRemoteNotificationKey];
  if (remoteNotification) { //是否有远程推送消息
    NSLog(@"remoteNotification:%@", remoteNotification[@"aps"][@"alert"][@"body"]);
  }
  }

App未杀死状态下点击推送消息栏

  - (void)jpushNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)(void))completionHandler  API_AVAILABLE(ios(10.0)){
NSDictionary * userInfo = response.notification.request.content.userInfo;
if([response.notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]]) {
[JPUSHService handleRemoteNotification:userInfo];
}
completionHandler();  // 系统要求执行这个方法
}
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。