自从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];
且NSUserNotificationAlertStyle
中的.plist
设置为“alert
”
但现在基本上关闭按钮的反应方式与actionButton
的反应相同吗?
答案 0 :(得分:2)
NSUserNotification具有可以管理通知标识符或hasActionButton值的属性,因此您可以使用if else在同一委托方法中处理关闭与操作按钮
- (void) userNotificationCenter:(NSUserNotificationCenter *)center didActivateNotification:(NSUserNotification *)notification{
}
答案 1 :(得分:1)
这对我有用..
您可以在didActivateNotification:
方法
- (void) userNotificationCenter:(NSUserNotificationCenter *)center didActivateNotification:(NSUserNotification *)notification
{
NSLog(@"Notification - Clicked");
[center removeDeliveredNotification: notification];
notification=nil;
}
其中center
是......
NSUserNotificationCenter *center = [NSUserNotificationCenter defaultUserNotificationCenter];
[center scheduleNotification:notification];