通知中心(OS X) - 作为标题变量

时间:2014-11-05 16:07:27

标签: objective-c macos nsusernotificationcenter

我在Notification Center的内容中遇到set变量的问题。这是我的代码

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];

如何将CFBundleVersion添加到通知内容中?

1 个答案:

答案 0 :(得分:1)

虽然这与通知中心无关,但您应该只使用CFBundleVersion创建一个字符串。

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

然后将标题变量设置为标题:

[notification setTitle:title];
相关问题