1

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()
    }
2
  • And what's printed by response.notification.request.content? Commented Jul 8, 2019 at 10:12
  • if let page = response.notification["aps"]["url"] as? String { print(url) } Commented Jul 8, 2019 at 10:12

2 Answers 2

4

You can try

let userInfo = response.notification.request.content.userInfo
print(userInfo["url"])
Sign up to request clarification or add additional context in comments.

Comments

2

like this:

let data = response.notification.request.content.userInfo
if let url = data["url"] as? String {

}

1 Comment

Thanks for your help, @Sh_Khan answered a bit before you so I accepted his but yours is also correct.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.