[英]How to read custom data from a notification in IOS swift
I'm building a small IOS application rendering a web application via WebKitView. 我正在构建一个小的IOS应用程序,通过WebKitView呈现Web应用程序。
I need to pass an extra information in the APNS payload to handle the routing of the app. 我需要在APNS有效负载中传递额外的信息来处理应用程序的路由。 Let's say your post has a new comment. 假设您的帖子有新评论。
When reading the apple documentation here . 在这里阅读Apple文档时。 I can see custom data can be added. 我可以看到可以添加自定义数据。
{
"aps" : {
"alert" : "You got your emails.",
"badge" : 9,
"sound" : "bingbong.aiff"
},
"url" : "https://domain.ext/post/1"
}
How can I access url
from: 如何从以下位置访问url
:
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
// if let page = response.notification["url"] as? String {
// print(url)
// }
completionHandler()
}
You can try 你可以试试
let userInfo = response.notification.request.content.userInfo
print(userInfo["url"])
like this: 像这样:
let data = response.notification.request.content.userInfo
if let url = data["url"] as? String {
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.