0

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?

2
  • There doesn't seem to be a type key in your notification's payload. Commented Oct 2, 2018 at 8:42
  • i have also tried with this gcm.notification.type but get nil value. @DávidPásztor Commented Oct 2, 2018 at 8:44

1 Answer 1

1

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
Sign up to request clarification or add additional context in comments.

1 Comment

how can we handle option key? i.e userInfo["AnyKey"] & it's optional it could be there or not.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.