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

最佳答案

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

斯威夫特3

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

对象
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

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

斯威夫特2
let build = NSBundle.mainBundle().infoDictionary?[kCFBundleVersionKey as String] as! String

09-03 23:44