【问题标题】:Notification Center (OS X) - variable as title通知中心 (OS X) - 作为标题的变量
【发布时间】:2014-11-05 16:07:27
【问题描述】:

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

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

【问题讨论】:

    标签: objective-c macos nsusernotificationcenter


    【解决方案1】:

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

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

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

    [notification setTitle:title];
    

    【讨论】:

      猜你喜欢
      • 2014-01-18
      • 2014-10-11
      • 2014-01-06
      • 1970-01-01
      • 2016-01-29
      • 2012-11-18
      • 1970-01-01
      • 1970-01-01
      • 2013-02-25
      相关资源
      最近更新 更多