我在互联网上搜索过,但找到的唯一方法是循环浏览
- (void)userNotificationCenter:(NSUserNotificationCenter *)center didDeliverNotification:(NSUserNotification *)notification
如下所示:https://stackoverflow.com/a/21365269/1795083
但是,我的应用有时会在短时间内显示多个通知,因此这不是真正有效也不有效。当按下垃圾按钮时,邮件应用程序如何处理它。至少必须有一个私人方法。有没有人遇到过它?提前致谢
答案 0 :(得分:8)
之后...嗯......“检查”邮件应用程序的代码......我在通知控制器类中发现了一个可疑的功能......
- (void)userNotificationCenter:(NSUserNotificationCenter *)center didDismissAlert:(NSUserNotification *)alert
我不知道为什么苹果不想将此功能添加到NSUserNotificationDelegate ...但我在我的应用程序中对此进行了测试并且确实有效!
答案 1 :(得分:3)
Swift> = 4 版本:
@objc
func userNotificationCenter(_ center: NSUserNotificationCenter, didDismissAlert notification: NSUserNotification)
确保添加@objc
注释,否则objective-C运行时将无法看到您的委托方法。