我正在向以下人员发送推送通知:
https://fcm.googleapis.com/fcm/send
格式为(在 php 中):
[
'to' => $token,
'data' => [
'key' => $val
],
'notification' => [
'title' => $title,
'body' => $message,
'badge' => $badge,
'sound' => 'default'
]
]
我的 iOS 应用程序接收并完美地显示推送,包括前台和后台。但我找不到如何访问data
在我的 AppDelegate 文件中,我有:
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any]) {
let aps = userInfo[AnyHashable("aps")] as! JsonObject
print(aps)
}
并且从print
语句中调试出来显示:
["sound": default, "badge": 1, "alert": {
body = "One flew over the cuckoo's nest";
title = "My Title";
}]
那么我的呢data: {key:val}
??
数据应该直接在userInfo
字典上可用,而不是在“aps”键上,你应该能够像这样访问它:
let customValue = userInfo["customKey"] as? String
如 Firebase文档所述,
通知消息的负载是键和值的字典。通过 APNs 发送的通知消息遵循 APNs 负载格式,如下所示:
{
"aps" : {
"alert" : {
"body" : "great match!",
"title" : "Portugal vs. Denmark",
},
"badge" : 1,
},
"customKey" : "customValue"
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句