objective-cmacosnsusernotificationcenter

Notification Center (OS X) - variable as title


I have problem with set variable in content of Notification Center. This is my code

NSUserNotification *notification = [[NSUserNotification alloc] init];
[notification setTitle:@"version of app"];
[notification setInformativeText:@"message"];
// Delay of pop-up notification
[notification setDeliveryDate:[NSDate dateWithTimeInterval:0 sinceDate:[NSDate date]]];
// Sound of notification
//[notification setSoundName:NSUserNotificationDefaultSoundName];
 NSUserNotificationCenter *center = [NSUserNotificationCenter defaultUserNotificationCenter];
[center scheduleNotification:notification];

How I can add CFBundleVersion to content of notification?


Solution

  • Although this has nothing to do with notification center, you should just create a string with the CFBundleVersion.

    NSString *version  = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"];
    NSString *title = [NSString stringWithFormat:@"Version %@", version];
    

    an then just set the title variable as the title:

    [notification setTitle:title];