【发布时间】:2017-08-23 04:46:46
【问题描述】:
我正在尝试检索在推送通知中发送的自定义数据。
自定义数据为:
[{"test":"01"}]
pushNotification 被接收为:
[AnyHashable("aps"): { alert = "Hello World!"; 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"] as!字符串
非常感谢任何帮助!
【问题讨论】: