簡體   English   中英

NSUserNotification關閉調用didActivateNotification

[英]NSUserNotification close calls didActivateNotification

從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

但現在基本上關閉按鈕的反應與actionButton反應方式相同?

NSUserNotification具有可以管理通知標識符或hasActionButton值的屬性,因此您可以使用if else在同一委托方法中處理關閉與操作按鈕的關系

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

這對我有用..

您可以刪除didActivateNotification: method中的通知

- (void) userNotificationCenter:(NSUserNotificationCenter *)center didActivateNotification:(NSUserNotification *)notification
{
    NSLog(@"Notification - Clicked");
    [center removeDeliveredNotification: notification];
    notification=nil;
}

center在哪里......

NSUserNotificationCenter *center = [NSUserNotificationCenter defaultUserNotificationCenter];
    [center scheduleNotification:notification];

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM