从推送通知中获取值
Get values from push notification
我已经在我的应用程序中实现了 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)
如何从通知中获取所有值?
您对负载的解析不正确。为什么您期望键 gcm.notification.type
的值是另一个 Dictionary
?它显然是 String
.
类型的单个值
let notificationType = userInfo["gcm.notification.type"] as? String
我已经在我的应用程序中实现了 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)
如何从通知中获取所有值?
您对负载的解析不正确。为什么您期望键 gcm.notification.type
的值是另一个 Dictionary
?它显然是 String
.
let notificationType = userInfo["gcm.notification.type"] as? String