2010-02-11 66 views

回答

119

請參閱Getting the Bundle’s Info.plist Data

[[NSBundle mainBundle] objectForInfoDictionaryKey:(NSString *)kCFBundleVersionKey]; 

應該爲您提供捆綁版本。

+0

完美,謝謝! – 2010-02-11 15:57:37

+0

可以在(複製)中找到更多信息: [我如何以編程方式檢查我們的應用程序的捆綁版本?](http://stackoverflow.com/questions/2657477/how-can-i-check-the我們的應用程序的版本 - 編程) – Guy 2014-10-28 10:28:37

+3

'[[NSBundle mainBundle] objectForInfoDictionaryKey:@「CFBundleShortVersionString」];'會得到你的短版本字符串,如下面的答案中所示(只發布objc版本) – smileham 2016-04-12 15:55:03

14

在斯威夫特你可以使用:

let bundleVersion: String = NSBundle.mainBundle().objectForInfoDictionaryKey(kCFBundleVersionKey as String) as! String 

或:

let bundleVersion: String = NSBundle.mainBundle().infoDictionary?[kCFBundleVersionKey as String] as! String 

如果你想在短包的版本字符串,你可以使用:

let shortBundleVersion: String = NSBundle.mainBundle().objectForInfoDictionaryKey("CFBundleShortVersionString") as! String 
-1
#define APP_VERSION [[NSBundle mainBundle] objectForInfoDictionaryKey:(NSString*)kCFBundleVersionKey]