我在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添加到通知内容中?
答案 0 :(得分:1)
虽然这与通知中心无关,但您应该只使用CFBundleVersion
创建一个字符串。
NSString *version = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"];
NSString *title = [NSString stringWithFormat:@"Version %@", version];
然后将标题变量设置为标题:
[notification setTitle:title];