繁体   English   中英

从[AnyHashable:Any]推送通知中获取数据

[英]Grab data from [AnyHashable: Any] Push notification

我正在尝试从推送通知中解析next_question_detail ,但是都失败了:

for data in notification.request.content.userInfo {
      print(data)
}
//Output

(key: AnyHashable("next_question_detail"), value: {"question_ar":"مرحبا","question":"hi","id":"5"})
(key: AnyHashable("errorCode"), value: 0)
(key: AnyHashable("google.c.a.e"), value: 1)
(key: AnyHashable("body"), value: )
(key: AnyHashable("userId"), value: 4)
(key: AnyHashable("title"), value: Wit)
(key: AnyHashable("gcm.message_id"), value: 0:1528865771984376%fa33e8cdfa33e8cd)
(key: AnyHashable("aps"), value: {
    alert =     {
        body = "";
        title = Wit;
    };
    badge = 0;
    sound = default;
})




        if let aps = notification.request.content.userInfo["next_question_detail"]! as? NSDictionary {
            print("aps",aps)
        }


        if let data = notification.request.content.userInfo["next_question_detail"] as? [String: String] {
            print("array",data)
        }

您可以使用以下代码执行此操作-

if let userInfo = userInfo as? [String: Any] {
    guard let next_question_detail = userInfo["next_question_detail"] as? [String: Any] else {
            return
       }
    print(next_question_detail)
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM