Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect "clear" notifications

if more than a minute pass from the time a user notification arrived to notification center, there is a "clear" option to dismiss one or more notifications at once from notification center.

How the iOS OS notify that the user tapped on "clear" to dismiss several notifications together?

like image 377
elkorb Avatar asked Jan 10 '18 16:01

elkorb


People also ask

How do you see previously cleared notifications on iPhone?

Notification Center shows your notifications history, allowing you to scroll back and see what you've missed. There are two ways to see your alerts from the Notification Center: From the Lock Screen, swipe up from the middle of the screen. From any other screen, swipe down from the center of the top of your screen.


1 Answers

Van's anwser goes straight into the right direction, but we do not need to implement the custom action to get what the question giver wanted.

If you create the category and pass it to the UNUserNotificationCenter you get a callback on the delegates didReceive function even if the user tabbed on the builtin Clear Button or the "X" Button on the content extension. The ResponeIdentifier will then be response.actionIdentifier == UNNotificationDismissActionIdentifier.

The Category must be something like that:

//Create the category...
UNNotificationCategory(identifier: "YourCustomIdentifier",
actions: [], intentIdentifiers: [], options: .customDismissAction)

//... and pass it to the UNUserNotificationCenter
UNUserNotificationCenter.current().setNotificationCategories(notificationCategories)

The category triggers the magic in the iOS framework and suddenly you get callbacks in your delegate. The delegate function should look like:

func userNotificationCenter(_ center: UNUserNotificationCenter,
                        didReceive response: UNNotificationResponse,
                        withCompletionHandler completionHandler: @escaping () -> Void) {
  if response.actionIdentifier == UNNotificationDismissActionIdentifier {
    // notification has been dismissed somehow        
  }
  completionHandler()
}
like image 127
KnechtRootrecht Avatar answered Sep 29 '22 11:09

KnechtRootrecht