简体   繁体   English

检测其他按钮单击(NSUserNotification)

[英]Detect Other Button click (NSUserNotification)

I've searched all over the internet but the only method found was by looping through 我在互联网上搜索过,但发现的唯一方法是循环播放

- (void)userNotificationCenter:(NSUserNotificationCenter *)center didDeliverNotification:(NSUserNotification *)notification

just as shown in: https://stackoverflow.com/a/21365269/1795083 如下所示: https//stackoverflow.com/a/21365269/1795083

However, my app sometimes displays multiple notifications at a short interval, so this isn't really efficient nor effective. 但是,我的应用程序有时会在短时间内显示多个通知,因此这不是真正有效也不是有效。 How does the mail app handle it when the trash button is pressed. 当按下垃圾按钮时,邮件应用程序如何处理它。 There has to be at least a private method that's called. 必须至少有一个被调用的私有方法。 Has anyone ever came across it? 有没有人遇到过它? Thanks in advance 提前致谢

After... uhm.... "checking" out the mail app's code... I found a suspicious function in their notification controller class... 之后...嗯....“检查”邮件应用程序的代码......我在他们的通知控制器类中发现了一个可疑的功能......

- (void)userNotificationCenter:(NSUserNotificationCenter *)center didDismissAlert:(NSUserNotification *)alert

I have no idea why apple don't want to add this function to the NSUserNotificationDelegate... but I tested this out in my app and it works!!! 我不知道为什么苹果不想将此功能添加到NSUserNotificationDelegate ...但我在我的应用程序中测试了它,它的工作原理!

Swift >= 4 version: Swift> = 4版本:

@objc
func userNotificationCenter(_ center: NSUserNotificationCenter, didDismissAlert notification: NSUserNotification)

Make sure you add the @objc annotation, otherwise the objective-C runtime won't be able to see your delegate method. 确保添加@objc注释,否则objective-C运行时将无法看到您的委托方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM