我使用的是以下代码:
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
// Insert code here to initialize your application
NSUserNotification *notification = [[NSUserNotification alloc] init];
[notification setTitle: @"Title"];
[notification setSubtitle: @"Subtitle"];
[notification setInformativeText: @"Informative Text"];
[notification setHasActionButton: YES];
[notification setActionButtonTitle: @"Action Button"];
[notification setOtherButtonTitle: @"Other Button"];
[notification setSoundName: NSUserNotificationDefaultSoundName];
[notification setDeliveryDate: [NSDate dateWithTimeIntervalSinceNow: 10]];
[[NSUserNotificationCenter defaultUserNotificationCenter] scheduleNotification: notification];
}我得到了,毫无疑问的是,

无操作按钮或其他按钮。
发布于 2012-07-27 03:29:28
这就是答案。
再次感谢freenode上的#macdev。

选择必须是"Alerts“才能有按钮。
发布于 2012-08-18 04:45:43
正如在前面的回答中所述,对于要显示的操作按钮,通知类型需要设置为alert。如果您希望将应用程序的默认通知样式设置为alert,则需要在info.plist中将key NSUserNotificationAlertStyle定义为值alert。
更多详情请参见苹果的info.plist keys reference:
NSUserNotificationAlertStyle指定通知样式应为banners、alerts或none。默认值为banners,这是推荐的样式。
发布于 2014-04-15 23:02:40
相反,对于其他答案,我们可以使用iTunes -它仍然显示“跳过”按钮,即使我们设置横幅的警报样式。所以我继续搜索,找到了this github repo,在那里Indragie Karunaratne在NSUserNotification私有头部中提供了一些有用的附加属性。您可以检查NSUserNotification_Private.h文件中的完整属性列表,但以横幅通知样式显示按钮的实际情况是
@property BOOL _showsButtons; // @dynamic _showsButtons;因此您只需将这一行添加到您的代码中
[notification setValue:@YES forKey:@"_showsButtons"];并且您的通知操作按钮将独立于警报样式。
https://stackoverflow.com/questions/11676017
复制相似问题