Objective c 如何删除通知横幅,但将其留在OS X上的通知中心?

Objective c 如何删除通知横幅,但将其留在OS X上的通知中心?,objective-c,xcode,macos,nsusernotification,nsusernotificationcenter,Objective C,Xcode,Macos,Nsusernotification,Nsusernotificationcenter,我现在做的是: [[NSUserNotificationCenter defaultUserNotificationCenter] removeAllDeliveredNotifications]; 因此,我的问题是,如何将通知保留在通知中心?您可以在执行操作时将其删除,然后再次添加,确保NSUserNotificationCenter委托类将shouldPresentNotification方法实现为NO (BOOL)用户通知中心:(NSUserNotificationCenter*)中心

我现在做的是:

[[NSUserNotificationCenter defaultUserNotificationCenter] removeAllDeliveredNotifications];

因此,我的问题是,如何将通知保留在通知中心?

您可以在执行操作时将其删除,然后再次添加,确保NSUserNotificationCenter委托类将shouldPresentNotification方法实现为NO

  • (BOOL)用户通知中心:(NSUserNotificationCenter*)中心 shouldPresentNotification:(NSUserNotification*)nsNotification{ 返回否; }

您可以随时删除它,然后再次添加它,确保NSUserNotificationCenter委托类将shouldPresentNotification方法实现为NO

  • (BOOL)用户通知中心:(NSUserNotificationCenter*)中心 shouldPresentNotification:(NSUserNotification*)nsNotification{ 返回否; }

实际上,这是非常不稳定的,因为只有当应用程序有焦点时,ShoulPresentNotification才会显示。实际上,这是非常不稳定的,因为ShoulPresentNotification只有在应用程序有焦点时才会显示。