Reputation: 578
I am setting multiple local Notification and I have set number of actions to notification . like snooze , show , close .
func didReceive(_ response: UNNotificationResponse, completionHandler completion: @escaping (UNNotificationContentExtensionResponseOption) -> Void) {
let id = response.notification.request.identifier
if response.actionIdentifier == "SnoozeId" {
completion(UNNotificationContentExtensionResponseOption.dismiss)
}}
On didReceive - if action is snooze - perform snooze and then i dismiss the notifiction . as i dismiss all the other notifications are gone from notification centre . If I have two Notification A and B . If i longpress and perform snooze on A . Both A and B are gone from notificaiton centre . it should dismiss only A.
Upvotes: 2
Views: 960
Reputation: 3352
Here are the results from testing with my app.
To better answer your question, please provide more information such as - the json of the notification and its userInfo (maybe you are grouping the notifications and dismissing all at once?) and what function you are calling that results in the call to didReceive(...).
If you call
self.extensionContext?.dismissNotificationContentExtension()
then it closes the content extension but does not dismiss it.
If you call:
self.extensionContext?.performNotificationDefaultAction()
then it completes the action and dismisses that single notification (not others). However, this opens the application, and you might not want to do this.
I have my delegate set up like this:
func didReceive(_ response: UNNotificationResponse, completionHandler completion: @escaping (UNNotificationContentExtensionResponseOption) -> Void) {
switch response.actionIdentifier {
case UNNotificationDismissActionIdentifier:
// Dismiss action stuff.
completion(.dismiss)
// To not dismiss
// completion(.doNotDismiss)
case UNNotificationDefaultActionIdentifier:
// Default action stuff.
// Let's say the user executed default action, we want to dismiss and forward the action.
completion(.dismissAndForwardAction)
break
default:
break
}
}
Upvotes: 2
Reputation: 2216
Tia may help you it was answered a while ago Only it was answered in objective C. The answer I think you’ll want to look at stores the notifications in a mutable array and removes the notifications from the array when necessary.
Upvotes: 0