【移动推送】iOS端通知扩展参数获取不到如何处理?
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。
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];
 
更多官方信息
EMAS官网介绍:https://www.aliyun.com/product/emas
Devops:https://www.aliyun.com/product/emascrash/mobile_devops
移动热修复:https://www.aliyun.com/product/hotfix
移动测试:https://www.aliyun.com/activity/emas/mqcexpert
移动推送:https://www.aliyun.com/product/cps
HTTPDNS:https://www.aliyun.com/product/httpdns
EMAS 控制台: https://emas.console.aliyun.com/products