开发者社区> 问答> 正文

【移动推送】iOS端通知扩展参数获取不到如何处理?

已解决

【移动推送】iOS端通知扩展参数获取不到如何处理?

展开
收起
EMAS支持组 2022-09-16 13:14:04 405 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];
    

    更多官方信息

    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

    2022-09-16 13:42:43
    赞同 展开评论 打赏
来源圈子
更多
收录在圈子:
基于阿里巴巴以及合作伙伴的最佳实践,围绕大前端、云原生领域的相关技术热点(小程序、Serverless、应用中间件、低代码、DevOps)展开行业探讨,与开发者一起探寻云原生时代应用研发的新范式。
问答排行榜
最热
最新

相关电子书

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

相关实验场景

更多