Mountain Lion OSX 10.8的Hello世界代码显示了像iChat这样的通知

MaX*_*MaX 15 cocoa objective-c osx-mountain-lion

是否有任何关于在Mountain Lion OSX 10.8(新通知中心)上显示hello world通知的示例.

只是为了增加视觉清晰度,这就是我所说的: 通知中心通知

MaX*_*MaX 43

在@Alexsander的一点帮助下,我终于找到了答案.

NSUserNotification *notification = [[NSUserNotification alloc] init];
[notification setTitle:@"Hello World"];
[notification setInformativeText:@"Hello world message"];
[notification setDeliveryDate:[NSDate dateWithTimeInterval:20 sinceDate:[NSDate date]]];
[notification setSoundName:NSUserNotificationDefaultSoundName];
NSUserNotificationCenter *center = [NSUserNotificationCenter defaultUserNotificationCenter];
[center scheduleNotification:notification];
Run Code Online (Sandbox Code Playgroud)

希望它能帮到人们


Ale*_*ers 10

查找NSUserNotificationNSUserNotificationCenter.

  • 这是一个无用的答案.这些页面上没有示例或链接. (7认同)