繁体   English   中英

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

[英]Notification Center (OS X) - variable as title

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

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

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

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

然后只需将title变量设置为title:

[notification setTitle:title];

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM