objective-c - NSUserNotification 关闭调用 didActivateNotification

标签 objective-c nsusernotification nsusernotificationcenter

从 MacOS 10.13 开始,每次我点击 NSUserNotification 上的关闭按钮时,它都会调用:

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

我如何防止这种情况或处理 closeaction 按钮

要创建通知,我会这样做:

NSUserNotification *notification = [[NSUserNotification alloc] init];
...
[notification setHasActionButton:false];
[[NSUserNotificationCenter defaultUserNotificationCenter] deliverNotification:notification];
[[NSUserNotificationCenter defaultUserNotificationCenter] setDelegate:(id)self];

并且 .plist 中的 NSUserNotificationAlertStyle 设置为“alert

但现在关闭按钮的 react 基本上与 actionButton 的 react 方式相同??

最佳答案

NSUserNotification 具有您可以管理通知标识符或 hasActionButton 值的属性,因此您可以在同一委托(delegate)方法中使用 if else 处理关闭按钮与操作按钮

- (void) userNotificationCenter:(NSUserNotificationCenter *)center didActivateNotification:(NSUserNotification *)notification{    
}

关于objective-c - NSUserNotification 关闭调用 didActivateNotification,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46610367/

相关文章:

ios - 在 AFNetworking V2.0 中使用多个参数进行 POST

objective-c - 如何使用 ios objective c 构建 webrtc

ios - iOS 10 中的 HTTP/2 服务器推送

应用程序处于事件状态时不显示 Swift NSUserNotification

ios - 移除 UIBarButtonItem 的文本阴影

objective-c - Mac Mountain Lion 从 CLI 应用发送通知

cocoa - 如何使用 Cocoa WebView 处理 HTML5 Web 通知?

objective-c - NSUserNotification 基于每个通知更改通知图像/ Logo

objective-c - Mac OS X NSUserNotificationCenter 通知获取取消事件/回调

cocoa - 删除DeliveredNotification : doesn't