gpt4 book ai didi

objective-c - NSUserNotification 关闭调用 didActivateNotification

转载 作者:搜寻专家 更新时间:2023-10-30 20:08:30 25 4
gpt4 key购买 nike

从 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

但现在关闭按钮的 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com