3.1.3. URL click processing
If you use Mindbox’s SDK to design push notifications, and need the URL that your user will be taken to when they click the push notification, go to AppDelegate
to redefine the userNotificationCenter didReceive response
function and retrieve the clicked notification data.
override func userNotificationCenter(
_ center: UNUserNotificationCenter,
didReceive response: UNNotificationResponse,
withCompletionHandler completionHandler: @escaping () -> Void
) {
super.userNotificationCenter(center, didReceive: response, withCompletionHandler: completionHandler)
let actionId = response.actionIdentifier
let userInfo = response.notification.request.content.userInfo as? [String: Any]
let buttons = userInfo?["buttons"] as? [[String: String]]
let clickedButton = buttons?.first(where: { $0["uniqueKey"] == actionId })
var url = ""
if let buttonUrl = clickedButton?["url"] {
url = buttonUrl
} else if let clickUrl = userInfo?["clickUrl"] as? String {
url = clickUrl
}
// Process the URL to be clicked
handleUrl(url)
}
Updated about 1 year ago