如何阅读PList的Bundle版本?

Rob*_*ner 48 iphone

有没有办法读取应用程序的捆绑plist文件,我想拉取Bundle版本的值.

Ole*_*ann 121

请参阅获取Bundle的Info.plist数据.

[[NSBundle mainBundle] objectForInfoDictionaryKey:(NSString *)kCFBundleVersionKey];
Run Code Online (Sandbox Code Playgroud)

应该得到捆绑版本.

  • `[[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"];`将为您提供短版本字符串,如下面的答案所示(仅发布objc版本) (3认同)

Pas*_*Kit 14

在Swift中你可以使用:

let bundleVersion = Bundle.main.object(forInfoDictionaryKeykCFBundleVersionKey as String) as! String
Run Code Online (Sandbox Code Playgroud)

要么:

let bundleVersion = Bundle.main.infoDictionary?[kCFBundleVersionKey as String] as! String
Run Code Online (Sandbox Code Playgroud)

如果需要短包版本字符串,可以使用:

let shortBundleVersion = Bundle.main.object(forInfoDictionaryKey:"CFBundleShortVersionString") as! String
Run Code Online (Sandbox Code Playgroud)