IOS应用程序,怎么以编程方式获得生成版本

内容来源于 Stack Overflow,并遵循CC BY-SA 3.0许可协议进行翻译与使用

  • 回答 (2)
  • 关注 (0)
  • 查看 (20)

有没有办法以编程的方式获得我的应用程序的构建版本?我需要能够检测用户何时通过AppStore更新了应用程序,以便执行一些调整代码。

提问于
用户回答回答于

在Xcode目标摘要的“Version”字段中设置的值位于以下位置:

SWIFT 3

let version = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as! String

objc

NSString *version = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];

SWIFT 2

let version = NSBundle.mainBundle().infoDictionary?["CFBundleShortVersionString"] as! String

以及“build”:

SWIFT 3

let build = Bundle.main.infoDictionary?[kCFBundleVersionKey as String] as? String

objc

NSString *build = [[[NSBundle mainBundle] infoDictionary] objectForKey:(NSString *)kCFBundleVersionKey];

SWIFT 2

let build = NSBundle.mainBundle().infoDictionary?[kCFBundleVersionKey as String] as! String
用户回答回答于

可以尝试使用infoDictionary

NSDictionary *infoDictionary = [[NSBundle mainBundle]infoDictionary];

NSString *version = infoDictionary[@"CFBundleShortVersionString"];
NSString *build = infoDictionary[(NSString*)kCFBundleVersionKey];
NSString *bundleName = infoDictionary[(NSString *)kCFBundleNameKey]; 

扫码关注云+社区