【问题标题】:Get values from push notification从推送通知中获取值
【发布时间】:2018-10-02 08:41:33
【问题描述】:

我已经在我的应用中实现了 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";

}]

我试图获得价值,但我得到它 nil 像这样,

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

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

【问题讨论】:

  • 您的通知负载中似乎没有 type 键。
  • 我也试过这个 gcm.notification.type 但得到 nil 值。 @DávidPásztor

标签: swift firebase apple-push-notifications


【解决方案1】:

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

let notificationType = userInfo["gcm.notification.type"] as? String

【讨论】:

  • 我们如何处理选项键?即 userInfo["AnyKey"] & 它是可选的,它可能存在或不存在。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-06-29
相关资源
最近更新 更多