如何阅读PList的Bundle版本?

时间:2010-02-11 14:19:01

标签: iphone

有没有办法读取应用程序的捆绑plist文件,我想要为Bundle版本提取值。

3 个答案:

答案 0 :(得分:121)

请参阅Getting the Bundle’s Info.plist Data

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

应该为您提供捆绑版本。

答案 1 :(得分:13)

在Swift中你可以使用:

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

答案 2 :(得分:-1)

#define APP_VERSION [[NSBundle mainBundle] objectForInfoDictionaryKey:(NSString*)kCFBundleVersionKey]