NSUserNotificationCenter dismiss notification

一世执手 提交于 2019-11-30 08:09:09

The Messages app is probably using the private NSUserNotificationCenter _removeAllDisplayedNotifications or _removeDisplayedNotification: method.

You can try to use these methods to test if this is what you are looking for. Just add this category interface to declare the methods:

@interface NSUserNotificationCenter (Private)
- (void)_removeAllDisplayedNotifications;
- (void)_removeDisplayedNotification:(NSUserNotification *)notification;
@end

Unfortunately, since these are undocumented methods, you can not use them in an app distributed through the App Store. If this is indeed what you are looking for, then you should file a bug and ask for these methods to become part of the public API.

As of 10.9, the following methods remove any displayed notifications:

// Clear a delivered notification from the notification center. If the 
// notification is not in the delivered list, nothing happens.
- (void)removeDeliveredNotification:(NSUserNotification *)notification;

// Clear all delivered notifications for this application from the 
// notification center.
- (void)removeAllDeliveredNotifications;

The behavior seems to have changed since 10.8, as any displayed notifications are removed as well when these methods are called (thanks @0xced for clarification).

removeDeliveredNotification is removing the displayed notification for me (on 10.11), the caveat being the identifier on the notification must be set.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!