我正试图在iOS应用程序(Swift(中使用Firebase检索推送通知中发送的"数据">
这是我用来发送通知的代码:
{
"to": "dWB537Nz1GA:APA91bHIjJ5....",
"data":
{
"message": "Offer!",
"mediaUrl": "https://upload.wikimedia.org/wikipedia/commons/thumb/2/2a/FloorGoban.JPG/1024px-FloorGoban.JPG"
},
"notification":
{
"body": "Enter your message",
"sound": "default"
}
}
我只实现了一种从通知中读取数据的方法:
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
//checked where I can get custom data which I sent but no success
let notification = response.notification.request.content.body
print("Notification recived content:(response.notification.request.content)")
print("userNotificationCenter : didReceive response body : (notification)")
print("userNotificationCenter : didReceive response user info : (response.notification.request.content.userInfo)")
print("userNotificationCenter : response : (response)")
completionHandler()
}
检查了上面的方法,在那里我可以获得我发送的自定义数据,但没有成功
我在很多地方寻找解决方案,但都没有成功。请帮助我检索自定义数据。
提前谢谢!
我在swift方面这样使用:
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any],
fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
if let menu = userInfo["Menu"] as? NSString {
print(menu)
}
Messaging.messaging().appDidReceiveMessage(userInfo)
completionHandler(UIBackgroundFetchResult.newData)
}
这是我用来发送通知的代码:
{
"to": "/topics/....",
"data":
{
"Menu": "Summary"
},
"notification":
{
"title": "Header",
"text": "Message",
"sound": "default"
}
}