Reputation: 2249
I am sending out a push notification to:
https://fcm.googleapis.com/fcm/send
formatted as (in php):
[
'to' => $token,
'data' => [
'key' => $val
],
'notification' => [
'title' => $title,
'body' => $message,
'badge' => $badge,
'sound' => 'default'
]
]
And my iOS app receives and displays the push perfectly, both foreground and background. But I can't find how to access data
In my AppDelegate file I have:
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any]) {
let aps = userInfo[AnyHashable("aps")] as! JsonObject
print(aps)
}
and the debug out from the print
statement displays:
["sound": default, "badge": 1, "alert": {
body = "One flew over the cuckoo's nest";
title = "My Title";
}]
So where is my data: {key:val}
??
Upvotes: 1
Views: 2676
Reputation: 5203
The data should be available directly on the userInfo
dictionary, not on the "aps" key and you should be able to access it like this:
let customValue = userInfo["customKey"] as? String
As stated on the Firebase documentation,
The payload of notification messages is a dictionary of keys and values. Notification messages sent through APNs follow the APNs payload format as below:
{
"aps" : {
"alert" : {
"body" : "great match!",
"title" : "Portugal vs. Denmark",
},
"badge" : 1,
},
"customKey" : "customValue"
}
Upvotes: 2