Ad

Get Values From Push Notification

- 1 answer

I have implemented firebase push notification in my app. Now I'm receiving notification details like this,

[AnyHashable("gcm.notification.details"): +12345, AnyHashable("gcm.notification.type"): video, AnyHashable("gcm.notification.group_name"): test, AnyHashable("gcm.message_id"): 0:1538469426956356%def3521bdef3521b, AnyHashable("google.c.a.e"): 1, AnyHashable("aps"): {
alert = "+12345";

}]

I have tried to get the value, but I'm getting it nil like this,

let notification = userInfo["type"] as? [AnyHashable: Any]
    print(notification)

How can I get all the values from the notification?

Ad

Answer

You're parsing the payload incorrectly. Why would you expect the value of the key gcm.notification.type to be another Dictionary? It is clearly a single value of type String.

let notificationType = userInfo["gcm.notification.type"] as? String
Ad
source: stackoverflow.com
Ad