iOS FCM 推送通知数据负载
Posted
技术标签:
【中文标题】iOS FCM 推送通知数据负载【英文标题】:iOS FCM push notification data payload 【发布时间】:2021-08-19 11:39:27 【问题描述】:我收到了来自 FCM 的推送通知,如下所示。如何从 AppDelegate 中的“数据”中获取数据
"to": "eTDYm1eJzUA-pRUNQ0pq9S:APA91CLfb1XQbsxUV0VIqTSV6A1YdXbKpRa9XkzZ6Px6Ww0-zQFU9OI0rgag_3Lwlu1yA1hbT-mQO6Ku37qNnuM6bKGfdOfAX-M0",
"notification":
"body":"body",
"title":"This is title",
"sound": "default",
"mutable_content": true
,
"data" :
"user_name": "user name",
提前谢谢你!
【问题讨论】:
【参考方案1】:Firebase 向我们发送 Map,我们应该将其转换为 [String: Any] 并从键中获取值
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void)
print("didReceive response TAPPED TO NOTIFICATION")
let userName = response.notification.request.content.userInfo["user_name"] as? [String : Any]
print(userName)
completionHandler()
【讨论】:
以上是关于iOS FCM 推送通知数据负载的主要内容,如果未能解决你的问题,请参考以下文章