从 MacOS 10.13 开始,每次我点击 NSUserNotification
上的关闭按钮时,它都会调用:
- (void) userNotificationCenter:(NSUserNotificationCenter *)center didActivateNotification:(NSUserNotification *)notification
我如何防止这种情况或处理 close
与 action
按钮
要创建通知,我会这样做:
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/