简体   繁体   English

无法从Swift中读取FCM消息内容

[英]Cannot read the FCM message content from Swift

I am trying to read the userInfo object of UNNotificationResponse. 我试图读取UNNotificationResponse的userInfo对象。 I tried casting it to Dictionary. 我尝试将它转换为Dictionary。 But it returns nil. 但它返回零。

I printed the object. 我打印了这个物体。

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

it prints following. 它打印以下。

{"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}}

But when I try to cast the object it returns nil. 但是当我尝试投射对象时,它返回nil。

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

to get the values ​​of userInfo["taskDoc"] you can do it like that 要获取userInfo["taskDoc"]的值,您可以这样做

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

If you wish to obtain the information of the notification you can do it in the following way 如果您希望获得通知的信息,可以通过以下方式进行

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM