How to detect when a user clears all notifications from Notification Center

To find out if he clears a single notification I can use the categoryIdentifier and actionIdentifier and and userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: u/escaping () -> Void) gets called.
Is there a method that gets called when the "clear" button from notification center is used? The result of this action on the button is that all notifications get cleared.
I want on that call to reset badge number to 0.
Not sure to understand exactly what you want.

Is there a method that gets called when the "clear" button from notification center is used?
I want on that call to reset badge number to 0.

Which badge is it ? When you clear, it is automatically reset to zero.
Is it a badge in your app ?

May have a look here for possible solution:
https://stackoverflow.com/questions/48191694/how-to-detect-clear-notifications
@Claude31

My intention is to keep the badge number(the red circle with the number that appears in the right upper corner of the app icon when you have something new waiting for you) in sync with the number of notifications displayed in Notification Center.

For example: if on Notification Center there are 5 notifications then I want the badge to say 5, if the user removes 2, I want the badge number to say 3.

Regarding the Stackoverflow question, I am familiar with the "solution" described there. There it describes how you can find out if a single notification is cleared. I ran the code and is working, so when the user clears out a notification I can decrease the badge by 1.
So far so good, but my problem is when the user clears all notifications at once, then instead of userNotificationCenter getting called multiple times for each notifiication, it is not called at all, and this is my problem because I don't know how to set badge to 0 when the user takes this action.
Apparently, there is no way to receive a notification when you clear all notifications (as explained in previous link).

So, maybe a work around would either to:
  • cyclically in your app to refresh its badge by checking how many notifications remain pending.

Find info here: https://stackoverflow.com/questions/49309223/run-a-periodic-task-in-background-independent-from-viewcontrollers
  • set a timer in each VC

example here: https ://www.hackingwithswift. com/example-code/system/how-to-make-an-action-repeat-using-timer

Frequency of one every 10 seconds would probably be enough (in termes of User experience), which would not drain too much resources.
How to detect when a user clears all notifications from Notification Center
 
 
Q