swift - 从推送通知中获取值
问题描述
我已经在我的应用程序中实现了 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)
如何从通知中获取所有值?
解决方案
您正在错误地解析有效负载。为什么你会期望 key 的 valuegcm.notification.type
是 another Dictionary
?这显然是 type 的单个值String
。
let notificationType = userInfo["gcm.notification.type"] as? String
推荐阅读
- javascript - 从下拉菜单中选择国家时突出显示国家
- vue.js - 如何在不点击任何按钮的情况下使用 VUE 生命周期钩子在 vue.js 中访问 API?
- javascript - React State 在渲染之前没有更新
- android - MIUI 更新到 12.0.1.0 稳定版后无法调试 Android 应用程序
- javascript - 绝对文本将在不同大小的图像的不同位置从底部开始
- aws-lambda - 获取参数 ScheduleExpression 在 aws lambda 上无效?
- angular - 如何优化从父服务注入子服务的Angular服务未使用代码
- html - 将边距应用于内部 div 并仍在父 div 内
- python - Pandas:Groupby 和每一步的价值收益
- python - 允许在 netmiko 的 send_command 中配置