Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cocoa/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Cocoa NSUserNotification未显示操作按钮_Cocoa_Osx Mountain Lion_Nsusernotification - Fatal编程技术网

Cocoa NSUserNotification未显示操作按钮

Cocoa NSUserNotification未显示操作按钮,cocoa,osx-mountain-lion,nsusernotification,Cocoa,Osx Mountain Lion,Nsusernotification,我正在使用以下代码: - (void)applicationDidFinishLaunching:(NSNotification *)aNotification { // Insert code here to initialize your application NSUserNotification *notification = [[NSUserNotification alloc] init]; [notification setTitle: @"Title"];

我正在使用以下代码:

- (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];
}
毫无疑问,我得到了


没有操作按钮或其他按钮。

答案如下

再次感谢freenode上的#macdev


选择需要是“警报”才能有按钮。

如前一个回答中所述,通知类型需要设置为警报才能显示操作按钮。如果要将应用程序的默认通知样式设置为警报,则需要在info.plist中使用值alert定义键NSUserNotificationAlertStyle

有关更多详细信息,请参阅苹果的:

NSUserNotificationAlertStyle指定通知样式应为横幅警报还是。默认值为横幅,这是推荐的样式


与其他答案相反的是,我们可以使用iTunes,它仍然显示“跳过”按钮,即使我们为横幅设置了警告样式。所以我继续搜索,并在NSUserNotification私有头中找到了where提供的一些有用的附加属性。您可以在NSUserNotification_Private.h文件中检查属性的完整列表,但以横幅通知样式显示按钮的实际值为

@property BOOL _showsButtons; // @dynamic _showsButtons;
因此,您可以将这一行添加到您的代码中

[notification setValue:@YES forKey:@"_showsButtons"];

您的通知操作按钮将独立于警报样式。

基于PARTISAN回复的魔法命令是:

notification.set_showsButtons_(True)

cha ching:)

你知道iOS上是否有类似的功能吗?我不相信这可以用当前的API配置为iOS中的UILocalNotifications。而且,需要为应用程序签名才能允许按钮。你是如何进入此屏幕的?如何使用“\u displayStyle”更改警报样式?如何为通知中的按钮添加选择器?如何使用“_displayStyle”更改警报样式?在PyObjCI中运行良好。我不能在Patrick的答案下方添加注释,因为我只是stackoverflow中的新手,但是@Dorian,您可以在此处检查我的答案。屏幕位于系统首选项中。