Is there a way to clear all Notifications that has notificationName = AVSystemController_SystemVolumeDidChangeNotification
from the NSNotificationCenter.defaultCenter()
?
I looked into many questions and I found a way to clear local notifications (UILocalNotification not NSNotifications) using `cancelLocalNotification(notification). I also found a way to clear ALL notifications from the notification center. I also looked into notification center documentation but didn't find something about that.
Note: Here is why I want it: I want to add an observer for volume change (when the user presses on the volume buttons) and I use (AVSystemController_SystemVolumeDidChangeNotification
).
However, when I add it, I have to wait half a second (dispatch_after
) to avoid any accumulating button presses from the user that happened right before (or while) adding the observer. In other words, the observer finds "old" notifications that were in the notification center before I tell it to start "observing".
So, I don't want to block main thread. Instead, I want to clear all the volume change notifications before I add the observer (this way I can be sure that no 'old' notification will trigger my actions).
I want to clear a specific type of notifications that has this notificationName.
Any ideas how to do it in Swift?