iOS应用,以编程方式获取构建版本

问题描述:

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

Is there a way to programmatically get the build version of my app? I need to be able to detect when the user has updated the app through the AppStore, in order to execute some code for adjustments

您在Xcode目标摘要的版本"字段中设置的值位于此处:

The value you set in the Xcode target summary's "Version" field is in here:

雨燕3

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

ObjC

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

雨燕2

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

和内部版本":

雨燕3

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

ObjC

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

雨燕2

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