我正在尝试检索推送通知中发送的自定义数据。
自定义数据是:
[{"测试":" 01"}]
pushNotification收到:
[AnyHashable(" aps"):{alert =" Hello World!&#34 ;; sound = default;},AnyHashable(" u"):[{" test":" 01"}],AnyHashable(" p" ):2Q]
接受我的推动如下:
func onPushAccepted(_ pushManager: PushNotificationManager!, withNotification pushNotification: [AnyHashable : Any]!, onStart: Bool) {
print("Push notification accepted: \(pushNotification!)")
if let aps = pushNotification["aps"] as? [String:Any] {
let customData = aps["u"] as! String
print("json String:\(customData)")
}
当我运行代码时,它会在线崩溃:
让customData = aps [" u"]为!串
非常感谢任何帮助!
答案 0 :(得分:0)
首先请原谅我,如果我不对,但你选错了钥匙。
if let aps = pushNotification["aps"] as? [String:Any]
应该是
if let data = pushNotification["u"] as? [String:Any]
然后你可以得到像这样的测试值
data["test"]
希望我是对的,这会对你有所帮助