Reputation: 632
I'm building a small IOS application rendering a web application via WebKitView.
I need to pass an extra information in the APNS payload to handle the routing of the app. Let's say your post has a new comment.
When reading the apple documentation here. 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:
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
// if let page = response.notification["url"] as? String {
// print(url)
// }
completionHandler()
}
Upvotes: 1
Views: 3678
Reputation: 59
like this:
let data = response.notification.request.content.userInfo
if let url = data["url"] as? String {
}
Upvotes: 2
Reputation: 100503
You can try
let userInfo = response.notification.request.content.userInfo
print(userInfo["url"])
Upvotes: 4