本人现发出推送通知予:
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}呢??
发布于 2020-10-01 21:28:54
数据应该直接放在userInfo字典上,而不是在"aps“键上,您应该可以这样访问它:
let customValue = userInfo["customKey"] as? String正如Firebase 文档所述,
通知消息的有效负载是键和值的字典。通过APN发送的通知消息遵循APN的有效负载格式如下:
{
"aps" : {
"alert" : {
"body" : "great match!",
"title" : "Portugal vs. Denmark",
},
"badge" : 1,
},
"customKey" : "customValue"
}https://stackoverflow.com/questions/64163212
复制相似问题