自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一样?
发布于 2017-10-12 05:16:33
NSUserNotification具有可用于管理通知标识符或hasActionButton值的属性,因此您可以在同一个委托方法中处理“关闭”和“动作”按钮。
- (void) userNotificationCenter:(NSUserNotificationCenter *)center didActivateNotification:(NSUserNotification *)notification{
}发布于 2017-10-10 11:36:01
这是为我工作..。
可以在didActivateNotification:方法中删除通知
- (void) userNotificationCenter:(NSUserNotificationCenter *)center didActivateNotification:(NSUserNotification *)notification
{
NSLog(@"Notification - Clicked");
[center removeDeliveredNotification: notification];
notification=nil;
}center在哪里..。
NSUserNotificationCenter *center = [NSUserNotificationCenter defaultUserNotificationCenter];
[center scheduleNotification:notification];https://stackoverflow.com/questions/46610367
复制相似问题