I have a deeplink from backend when i recieve notification. The case is whenever i try to clear the notification center e.g swipe clear, the clear button redirect to my deeplink. the behavior when you swipe clear should remove the notification from the notification center. But in my case is not.
And it happend in selected device and in my device is not happening, i try to solve the clear button from this stackoverflow question clear notification
but i try this method, still not work.
this i setup my UNNotificationCenter in appDelegate
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
completionHandler([.alert, .badge, .sound])
let userInfo = notification.request.content.userInfo
appScreenViewModel.handlePushNotificationInApp(userInfo: userInfo)
guard let aps = userInfo["aps"] as? [String: Any], let category = aps["category"] as? String else { return }
let clearAction = UNNotificationAction(identifier: UNNotificationDismissActionIdentifier, title: "Clear", options: [])
UNNotificationCategory(identifier: category, actions: [clearAction], intentIdentifiers: [], options: .customDismissAction)
}
And this is i handle the notification in userNotification didReceive response
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
MoEngage.sharedInstance().userNotificationCenter(center, didReceive: response)
let userInfo = response.notification.request.content.userInfo
appScreenViewModel.handlePushNotification(userInfo: userInfo)
if response.actionIdentifier == UNNotificationDismissActionIdentifier {
UNUserNotificationCenter.current().removeAllDeliveredNotifications()
}
}
And this is the payload i recieve
"aps": {
"alert": {
"title": "Notification Title",
"subtitle": "Notification Subtitle",
"body": "Notification Body"
},
"badge": 1,
"sound": "default",
"category": "INVITE_CATEGORY",
"content-available": 1,
"mutable-content": 1
}
Where did i do wrong?
Sorry i found a solution already, if you didn't want redirect to deeplink when you tap clear. what i do is like this
if response.actionIdentifier != UNNotificationDismissActionIdentifier {
appScreenViewModel.handlePushNotification(userInfo: userInfo)
}