正在从自定义负载中获取数据 Swift
Fetching data from Custom Payload Swift
我正在使用自定义负载进行通知,我收到了通知,但无法从 Key["data"] 中获取。
这是我的有效载荷代码
{
"Simulator Target Bundle": "com.xyz.zyxapp",
"aps" : {
"alert" : "It's a notification with custom payload!",
"badge" : 1,
"content-available" : 0
},
"data" :{
"title" : "Game Request",
"body" : "Bob wants to play poker",
"action-loc-key" : "PLAY"
},
}
我正在尝试从 didreceive 方法访问数据
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void)
{
print(response.notification.request.content.body)
}
结果是:这是一个带有自定义负载的通知!
如果有人可以帮助我,我将不胜感激。
提前致谢
问候。
在通知的 userInfo
属性 而不是正文中解析自定义数据。 userInfo
是与通知关联的自定义信息的字典。
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
let userInfo = response.notification.request.content.userInfo
if let data = userInfo["data"] as? [String: Any] {
//
//Do your parsing here..
}
}
我正在使用自定义负载进行通知,我收到了通知,但无法从 Key["data"] 中获取。 这是我的有效载荷代码
{
"Simulator Target Bundle": "com.xyz.zyxapp",
"aps" : {
"alert" : "It's a notification with custom payload!",
"badge" : 1,
"content-available" : 0
},
"data" :{
"title" : "Game Request",
"body" : "Bob wants to play poker",
"action-loc-key" : "PLAY"
},
}
我正在尝试从 didreceive 方法访问数据
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void)
{
print(response.notification.request.content.body)
}
结果是:这是一个带有自定义负载的通知! 如果有人可以帮助我,我将不胜感激。 提前致谢 问候。
在通知的 userInfo
属性 而不是正文中解析自定义数据。 userInfo
是与通知关联的自定义信息的字典。
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
let userInfo = response.notification.request.content.userInfo
if let data = userInfo["data"] as? [String: Any] {
//
//Do your parsing here..
}
}