【发布时间】:2019-09-04 10:10:31
【问题描述】:
有没有办法读取应用程序捆绑的 plist 文件,我想提取 Bundle 版本的值。
【问题讨论】:
标签: iphone
有没有办法读取应用程序捆绑的 plist 文件,我想提取 Bundle 版本的值。
【问题讨论】:
标签: iphone
见Getting the Bundle’s Info.plist Data。
[[NSBundle mainBundle] objectForInfoDictionaryKey:(NSString *)kCFBundleVersionKey];
应该给你捆绑版本。
【讨论】:
[[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"]; 将为您提供简短的版本字符串,如下面的答案所示(仅发布 objc 版本)
在 Swift 中你可以使用:
let bundleVersion = Bundle.main.object(forInfoDictionaryKeykCFBundleVersionKey as String) as! String
或:
let bundleVersion = Bundle.main.infoDictionary?[kCFBundleVersionKey as String] as! String
如果你想要简短的捆绑版本字符串,你可以使用:
let shortBundleVersion = Bundle.main.object(forInfoDictionaryKey:"CFBundleShortVersionString") as! String
【讨论】:
#define APP_VERSION [[NSBundle mainBundle] objectForInfoDictionaryKey:(NSString*)kCFBundleVersionKey]
【讨论】: