Firebase Notification.request.content中的图像键

问题描述 投票:0回答:1

[这是Firebase的通知响应,它在字典中,我想访问“ fcm_options”,“ image”值。谁能指导我如何快速访问它。

  "gcm.n.e" : "1",
  "google.c.a.udt" : "0",
  "google.c.a.e" : "1",
  "gcm.message_id" : "1598126925155526",
  "google.c.a.ts" : "1587313425",
  "google.c.sender.id" : "162801098578",
  "aps" : {
    "alert" : {
      "title" : "Test",
      "body" : "Test"
    },
    "mutable-content" : "1"
  },
  "fcm_options" : {
    "image" : "https:\/\/www.indiewire.com\/wp-content\/uploads\/2017\/12\/wonder-woman-759.jpg?w=759"
  },
  "google.c.a.c_id" : "3173813338411805539"
}

预先感谢

ios swift dictionary firebase-notifications
1个回答
0
投票

如果Dictionary为,

let dict: [String:Any] = [
  "gcm.n.e": "1",
  "google.c.a.udt": "0",
  "google.c.a.e": "1",
  "gcm.message_id": "1598126925155526",
  "google.c.a.ts": "1587313425",
  "google.c.sender.id": "162801098578",
  "aps": [
    "alert": [
      "title": "Test",
      "body": "Test"
    ],
    "mutable-content": "1"
  ],
  "fcm_options": [
    "image": "https://www.indiewire.com/wp-content/uploads/2017/12/wonder-woman-759.jpg?w=759"
  ],
  "google.c.a.c_id": "3173813338411805539"
]

您可以从fcm_options中获取imagedict

if let fcmOptions = dict["fcm_options"] as? [String:Any], let image = fcmOptions["image"] as? String {
    print(image)
    //use image here...
}
© www.soinside.com 2019 - 2024. All rights reserved.