2

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.

mfaani
  • 33,269
  • 19
  • 164
  • 293
Akash Shindhe
  • 558
  • 4
  • 16

2 Answers2

2

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
    }
}
Joshua Wolff
  • 2,687
  • 1
  • 25
  • 42
0

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.

Jake
  • 2,126
  • 1
  • 10
  • 23
  • 1
    Thanks for the reply jake but its not i am looking for . The link you shared explains how to cancel the notification . I need to know how remove it from notification centre after user performs some action . – Akash Shindhe Feb 15 '18 at 15:56
  • @AkashShindhe. I am also facing the same problem. Just dismiss my notification. But I want to remove it without entering the parent app. Did you found a solution? please response – Shourob Datta Jul 11 '20 at 08:54