gpt4 book ai didi

swift - 无法从 Swift 读取 FCM 消息内容

转载 作者:行者123 更新时间:2023-11-30 10:43:03 24 4
gpt4 key购买 nike

我正在尝试读取 UNNotificationResponse 的 userInfo 对象。我尝试将其转换为字典。但它返回零。

我打印了该对象。

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

关于swift - 无法从 Swift 读取 FCM 消息内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56393390/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com