Search code examples
objective-ccocoaosx-mountain-lion

Hello world code for Mountain Lion OSX 10.8 showing notification like iChat


Is there any example for showing a hello world notification on Mountain Lion OSX 10.8 (the new notification center).

Just to add visual clarity here is what I am talking about: Notification Center Notification


Solution

  • I finally found answer after a little help from @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];
    

    Hope it helps people