从推送通知中获取值

时间:2018-10-02 08:41:34

标签: swift firebase apple-push-notifications

我已在我的应用中实现了Firebase推送通知。现在,我收到这样的通知详细信息,

[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";

}]

我试图获得价值,但我却没有得到这样的价值,

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

如何从通知中获取所有值?

1 个答案:

答案 0 :(得分:1)

您错误地解析了有效负载。您为什么期望键gcm.notification.type的值是另一个Dictionary?显然,它是String类型的单个值。

let notificationType = userInfo["gcm.notification.type"] as? String
相关问题