我正在尝试读取UNNotificationResponse的userInfo对象。我尝试将其投射到Dictionary。但它返回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>
答案 0 :(得分:0)
要获取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