ios - 无法访问 gcm 数据响应

标签 ios swift firebase google-cloud-messaging firebase-cloud-messaging

如何访问(“gcm.notification.data”)值? 我可以使用以下代码访问(“aps”)值:

    if let aps = userInfo["aps"] as? NSDictionary {
                if let alert = aps["alert"] as? NSDictionary {
                    if let title = alert["title"] as? NSString,let body = alert["body"] as? NSString{
print(title)
print(body)
}

消息回复

    [AnyHashable("gcm.notification.data"): {"status":"7809","body":"sgjh body"}, 
AnyHashable("aps"): {
    alert =     {
        body = "sgjh body";
        title = "yfguhj title";
    };
    badge = 1;
    "content-available" = 1;
    sound = default;
}]

最佳答案

if let gcmData = userInfo["gcm.notification.data"] as? NSDictionary {

    for (key, value) in gcmData {

        guard let key = key as? String else { continue }

        switch (key, value) {
        case ("status", let aValue as Double): print(aValue)
        case ("body", let aValue as String): print(aValue)
        default: continue
        }
    }
}

关于ios - 无法访问 gcm 数据响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52380247/

相关文章:

ios - 如何修复此错误 : 'Foundation._GenericObjCError error 0. '

ios - 具有相同数据源的多个 UICollectionView

android - 将 Android 游戏连接到 iOS 游戏中心

ios - 将十六进制代码转换为日期 (BLE) - 算法

ios - 来自 UIActivityType 的 UIActivity

node.js - where is or What is the serviceAccountKey.json 是firebase实时数据库的 Node js示例

ios - 访问核心数据镜像中的外部数据引用属性

swift - 如何使用 Xcode 7 使用 Swift 代码将 Button 放入 SpriteKit 中?

Firebase服务不会更新Service Worker

android - 找不到与 com.google.android.gms :play-services-base:[15. 0.1,16.0.0 匹配的任何版本)