无法从 Swift 读取 FCM 报文内容



我正在尝试读取UNNotificationResponse的用户信息对象。我尝试将其转换为字典。但它返回 nil。

我打印了对象。

let userInfo = response.notification.request.content.userInfo
if let messageID = userInfo["taskDoc"] {
            print("Message ID: (messageID)")
}

它打印以下内容。

{"assigned_user":"+sddadad","assigned_user_image":"","assigned_user_name":"Chandima 68","assignee_comment":"","checklist":[],"created_at":{"_seconds":1559297826,"_nanoseconds":851644000},"created_by":"+94711555268","description":"","due_at":{"_seconds":1559297824,"_nanoseconds":745725000},"group_id":"I0W3Nrrr0IpUVaI33SnU","group_name":"Photo Group new","status":0,"title":"Ada","updated_at":{"_seconds":1559297826,"_nanoseconds":851644000}}

但是当我尝试转换对象时,它返回 nil。

let task = userInfo["taskDoc"] as? Dictionary<String, Any>

要获取userInfo["taskDoc"]的值,您可以这样做

let test = userInfo["taskDoc"] as? NSDictionary

如果您希望获得通知信息,您可以通过以下方式进行

let title = response.notification.request.content.title
let subtitle = response.notification.request.content.subtitle
let body = response.notification.request.content.body

相关内容

  • 没有找到相关文章

最新更新