3

由于MacOS的10.13每次我点击一个NSUserNotification关闭按钮调用:NSUserNotification收市话费didActivateNotification

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

我怎样才能避免这种情况或处理close VS的action按钮

要创建的通知我做的:

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

NSUserNotificationAlertStyle被设置为“alert

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

回答

1

NSUserNotification拥有财产,从中可以管理通知标识符或hasActionButton值,因此您可以使用相同的委托方法处理close或action按钮

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

什么是财产? – maxisme

+0

https://developer.apple.com/documentation/foundation/nsusernotification?language=objc这里您将获得您可以使用的属性详细信息并编写条件操作。 –

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];