我正在使用此代码:
- (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];
}
Run Code Online (Sandbox Code Playgroud)
我得到了,但没有失败,

没有操作按钮或其他按钮.
嘿,我正在玩一个小的可可应用程序并在Mountain Lion中使用新的Notification Center API.但是,我的应用程序现在存在于通知中心设置中,以及日历,消息等.
因为只是我在玩,我希望它现在从列表中消失,但我无论如何都找不到它,尝试了几件事,拖出来,按住alt +右键等等.有谁知道填充该列表的(可能是)plist位于何处?
Mac基础知识:通知会通知您,可以使用文本输入字段创建交互式警报:
例如,您可以直接通过通知回复聊天.
我该如何实现它?例如,我有一个通知:
let notification = NSUserNotification.init()
notification.hasActionButton = true
notification.actionButtonTitle = "Agree"
notification.title = "Header"
notification.informativeText = "Text."
NSUserNotificationCenter.default.deliver(notification)
Run Code Online (Sandbox Code Playgroud)