开发者社区> 问答> 正文

移动推送 iOS : iOS端 通知扩展参数获取不到,如何解决?

移动推送 iOS : iOS端 通知扩展参数获取不到,如何解决?

展开
收起
保持可爱mmm 2020-03-27 23:29:07 835 0
1 条回答
写回答
取消 提交回答
  • iOS 通知 payload 字段 通知扩展参数的获取参考如下:

    // 基于 OpenAPI 高级接口推送 iOS 通知 PushRequest pushRequest = new PushRequest(); pushRequest.setAppKey(appKey); pushRequest.setTarget("DEVICE"); pushRequest.setTargetValue("xxxxxx"); pushRequest.setPushType("NOTICE"); pushRequest.setDeviceType("iOS"); pushRequest.setTitle("Push Title"); pushRequest.setBody("Push Body"); // 通知扩展属性通过json map格式传入 // 这里额外属性为key1 = value1, key2 = value2 pushRequest.setiOSExtParameters("{"key1":"value1","key2":"value2"}") 客户端获取额外参数 参考如下: iOS 10 + 设备:

    • (void)handleiOS10Notification:(UNNotification *)notification { UNNotificationRequest *request = notification.request; UNNotificationContent *content = request.content; NSDictionary *userInfo = content.userInfo; // 通知时间 NSDate *noticeDate = notification.date; // 标题 NSString *title = content.title; // 副标题 NSString *subtitle = content.subtitle; // 内容 NSString *body = content.body; // 角标 int badge = [content.badge intValue]; // 取得通知自定义字段内容,例:获取key为"key1"和"key2"的内容 NSString *extKey1 = @"key1"; NSString *extKey2 = @"key2"; NSString *extValue1 = [userInfo valueForKey:extKey1]; NSString *extValue1 = [userInfo valueForKey:extKey1]; // 通知打开回执上报 [CloudPushSDK sendNotificationAck:userInfo]; NSLog(@"Notification, date: %@, title: %@, subtitle: %@, body: %@, badge: %d, extras: [%@ = %@, %@ = %@].", noticeDate, title, subtitle, body, badge, extKey1, extValue1, extKey2, extValue2); } iOS 10 -

    • (void)application:(UIApplication*)application didReceiveRemoteNotification:(NSDictionary*)userInfo { NSLog(@"Receive one notification."); // 取得APNS通知内容 NSDictionary *aps = [userInfo valueForKey:@"aps"]; // 内容 NSString *content = [aps valueForKey:@"alert"]; // badge数量 NSInteger badge = [[aps valueForKey:@"badge"] integerValue]; // 播放声音 NSString *sound = [aps valueForKey:@"sound"]; // 取得通知自定义字段内容,例:获取key为"key1"和"key2"的内容 NSString *extKey1 = @"key1"; NSString *extKey2 = @"key2"; NSString *extValue1 = [userInfo valueForKey:extKey1]; NSString *extValue1 = [userInfo valueForKey:extKey1]; NSLog(@"content = [%@], badge = [%ld], sound = [%@], Extras = [%@ = %@, %@ = %@]", content, (long)badge, sound, extKey1, extValue1, extKey2, extValue2); // iOS badge 清0 application.applicationIconBadgeNumber = 0; // 通知打开回执上报 // [CloudPushSDK handleReceiveRemoteNotification:userInfo];(Deprecated from v1.8.1) [CloudPushSDK sendNotificationAck:userInfo];

    2020-03-27 23:32:52
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
手淘iOS性能优化探索 立即下载
From Java/Android to Swift iOS 立即下载
深入剖析iOS性能优化 立即下载