我正在与Xcode 9.4.1 (9F2000)和一起工作Swift 3。
我将这些数据用于推送通知:
{
"aps":{
"alert":{
"title":"Hello",
"body":"How are you?"
},
"badge":0,
"sound":"default",
"my_value":"This is a test!"
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的功能:
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
let action = response.actionIdentifier
let request = response.notification.request
let content = request.content
print("payload data: \(action)\(request)\(content)\n")
completionHandler()
}
Run Code Online (Sandbox Code Playgroud)
我认为自定义有效负载应该在request或 中content。但是在执行时print("payload data: \(action)\(request)\(content)\n"),它不会出现。
我究竟做错了什么?
你可以带着字典
let content = response.notification.request.content.userInfo
if let aps = content["aps"] as? [String: AnyObject] {
let myValue = aps["my_value"]
// DO STUFF, in myValue you will find your custom data
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2259 次 |
| 最近记录: |