解析来自Apple Push Notification的数据

麦可

我有通过Firebase发送的推送通知,当用户执行操作时,会有一个php脚本将推送发送到关联的FCM令牌。收到了推送通知,但是我试图从“ gcm.notification.payload”键中获取信息。我尝试将userInfo强制转换为Dictionary,NSDictionary,[String:Any],JSON,但没有任何效果。当我尝试说有效负载[“ type”]。string时,值为nil。这是我能够从有效负载字典中获取某些信息的最接近的地方,其中通知是收到的UNNotification:

let userInfo = notification.request.content.userInfo


let json = JSON(notification.request.content.userInfo)
guard let gcmNotificationPayload = json["gcm.notification.payload"].string else { return }
let payload = JSON(gcmNotificationPayload)
print("json \(json)")
print("payload \(payload)")
print("\(notification.request.content.userInfo)")

控制台输出:

  json {
      "gcm.message_id" : "0:1523811750249807%3990eb5d3990eb5d",
      "aps" : {
        "sound" : "default",
        "badge" : 1,
        "alert" : {
          "body" : "Tap to Open Herds List",
          "title" : "test4 test has added you to a herd!"
        }
      },
      "gcm.notification.payload" : "{\"image\":\"https:\\\/\\\/www.test.com\\\/images\\\/users\\\/417\\\/5acd085c97c3a.jpg\",\"type\":\"6\",\"title\":\"test4 test has added you to a herd!\",\"message\":\"Tap to Open Herds List\"}"
    }

    payload {"image":"https:\/\/www.test.com\/images\/users\/417\/5acd085c97c3a.jpg","type":"6","title":"test4 test has added you to a herd!","message":"Tap to Open Herds List"}

    [AnyHashable("gcm.message_id"): 0:1523811750249807%3990eb5d3990eb5d, AnyHashable("aps"): {
        alert =     {
            body = "Tap to Open Herds List";
            title = "test4 test has added you to a herd!";
        };
        badge = 1;
        sound = default;
    }, AnyHashable("gcm.notification.payload"): {"image":"https:\/\/www.test.com\/images\/users\/417\/5acd085c97c3a.jpg","type":"6","title":"test4 test has added you to a herd!","message":"Tap to Open Herds List"}]
麦可

将let有效负载行更改为此可以解决问题,并且此记录使用了SwiftyJSON:

let payload = JSON.init(parseJSON: gcmNotificationPayload)

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

使用Java和REST发送Apple Push Notification时出现问题

Apple Push Notification身份验证密钥(沙箱和生产)

Apple Push Notification服务SSL(沙盒和生产)证书是否通用?

使用来自Push Notification IntentService的GoogleApiClient将数据发送到Android Wear

尝试连接到Apple Push Notification Service时为什么会出现OpenSSL错误?

如何使用Apple Push Notification P12证书文件通过代码设置ios平台?

Apple Push Notification服务必须合并新的根证书(AAACertificateServices)-APNS证书更新

Apple Push Notification Service服务器证书更新

如何在Mac上使用Apple Push Notification?

Apple Push Notification无法与临时版本一起使用,不能在开发中使用

Mac更改后,Apple Push Notification不起作用

解析来自googleapi的数据

离线Apple Push Notification有效性

Apple Push Notification设置“远程通知”方法会覆盖其他方法

Mac for Application上的Apple Push Notification不在Appstore上

Apple Push Notification的App Delegate调用不显示ViewController

我应该使用Apple Push Notification还是仅在后台为简单应用程序提取数据?

Apple Push Notification到达后,无法通过滑动锁定屏幕(无密码)打开应用程序

我应该在我的iOS Push Notification App中使用核心数据吗?

对Apple Push Notification Services进行故障排除

Apple Push Notification-最终用户试图充当CA

如何解析Firebase JSON Push方法中的数据

Apple Push Notification Service已连接,但未收到任何通知

Apple Push Notification Service在生产中不起作用

Xcode免费配置:“ Apple Push Notification”功能仅适用于注册了Apple Developer Program的用户

Apple Push Notification Service SSL(沙盒和生产)-尚未收到生产通知吗?

解析来自网站的数据

解析来自 Postman 的 JSON 数据

解析来自 Firebase 的数据