0

我在通知中心的内容中设置变量有问题。这是我的代码

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 添加到通知内容?

4

1 回答 1

1

虽然这与通知中心无关,但您应该只创建一个带有CFBundleVersion.

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

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

[notification setTitle:title];
于 2014-11-05T16:16:49.957 回答