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();  // 系统要求执行这个方法
}

你可能感兴趣的:(iOS开发中App在杀死状态下点击推送获取推送内容)