文档

iOS端通知扩展参数获取不到如何处理?

更新时间:

iOS通知payload字段通知扩展参数的获取参考如下:

  1. // 基于 OpenAPI 高级接口推送 iOS 通知
  2. PushRequest pushRequest = new PushRequest();
  3. pushRequest.setAppKey(appKey);
  4. pushRequest.setTarget("DEVICE");
  5. pushRequest.setTargetValue("xxxxxx");
  6. pushRequest.setPushType("NOTICE");
  7. pushRequest.setDeviceType("iOS");
  8. pushRequest.setTitle("Push Title");
  9. pushRequest.setBody("Push Body");
  10. // 通知扩展属性通过json map格式传入
  11. // 这里额外属性为key1 = value1, key2 = value2
  12. pushRequest.setiOSExtParameters("{\"key1\":\"value1\",\"key2\":\"value2\"}")

客户端获取额外参数参考如下:

iOS 10 +设备:

  1. - (void)handleiOS10Notification:(UNNotification *)notification {
  2. UNNotificationRequest *request = notification.request;
  3. UNNotificationContent *content = request.content;
  4. NSDictionary *userInfo = content.userInfo;
  5. // 通知时间
  6. NSDate *noticeDate = notification.date;
  7. // 标题
  8. NSString *title = content.title;
  9. // 副标题
  10. NSString *subtitle = content.subtitle;
  11. // 内容
  12. NSString *body = content.body;
  13. // 角标
  14. int badge = [content.badge intValue];
  15. // 取得通知自定义字段内容,例:获取key为"key1"和"key2"的内容
  16. NSString *extKey1 = @"key1";
  17. NSString *extKey2 = @"key2";
  18. NSString *extValue1 = [userInfo valueForKey:extKey1];
  19. NSString *extValue1 = [userInfo valueForKey:extKey1];
  20. // 通知打开回执上报
  21. [CloudPushSDK sendNotificationAck:userInfo];
  22. NSLog(@"Notification, date: %@, title: %@, subtitle: %@, body: %@, badge: %d, extras: [%@ = %@, %@ = %@].", noticeDate, title, subtitle, body, badge, extKey1, extValue1, extKey2, extValue2);
  23. }

iOS 10 -

  1. - (void)application:(UIApplication*)application didReceiveRemoteNotification:(NSDictionary*)userInfo {
  2. NSLog(@"Receive one notification.");
  3. // 取得APNS通知内容
  4. NSDictionary *aps = [userInfo valueForKey:@"aps"];
  5. // 内容
  6. NSString *content = [aps valueForKey:@"alert"];
  7. // badge数量
  8. NSInteger badge = [[aps valueForKey:@"badge"] integerValue];
  9. // 播放声音
  10. NSString *sound = [aps valueForKey:@"sound"];
  11. // 取得通知自定义字段内容,例:获取key为"key1"和"key2"的内容
  12. NSString *extKey1 = @"key1";
  13. NSString *extKey2 = @"key2";
  14. NSString *extValue1 = [userInfo valueForKey:extKey1];
  15. NSString *extValue1 = [userInfo valueForKey:extKey1];
  16. NSLog(@"content = [%@], badge = [%ld], sound = [%@], Extras = [%@ = %@, %@ = %@]", content, (long)badge, sound, extKey1, extValue1, extKey2, extValue2);
  17. // iOS badge 清0
  18. application.applicationIconBadgeNumber = 0;
  19. // 通知打开回执上报
  20. // [CloudPushSDK handleReceiveRemoteNotification:userInfo];(Deprecated from v1.8.1)
  21. [CloudPushSDK sendNotificationAck:userInfo];
  • 本页导读 (0)
文档反馈