8

我正在使用以下代码在 OS X 上显示本地 NSUserNotification:

NSUserNotification *notification = [[NSUserNotification alloc] init];
[notification setTitle:@"Some Title"];
[notification setHasActionButton:YES];
[notification setActionButtonTitle:@"Snooze"];

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

我面临的问题是,如果单击通知本身或“操作按钮”,我只会收到一条消息,但如果单击“其他”按钮(关闭按钮),我还想执行一些代码。如果 NSUserNotification 被解除或单击关闭按钮时,有什么方法可以得到通知?userNotificationCenter:didActivateNotification:单击关闭按钮时不会触发NSUserNotificationCenter 。

如果这是不可能的,有没有办法像 Apple 在其提醒应用程序中使用的那样创建一个下拉按钮(如果用户按住操作按钮,则会打开一个菜单)。

谢谢!

4

0 回答 0