3

由于 MacOS 10.13 每次我单击NSUserNotification它调用的关闭按钮时:

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

我怎样才能防止这种情况或处理closevsaction按钮

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

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

NSUserNotificationAlertStyle.plist设置为“ alert

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

4

2 回答 2

2

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

- (void) userNotificationCenter:(NSUserNotificationCenter *)center didActivateNotification:(NSUserNotification *)notification{    
}
于 2017-10-12T05:16:33.273 回答
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];
于 2017-10-10T11:36:01.583 回答