Вы можете получить версию и номера сборки следующим образом:
let version = Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString") as! String
let build = Bundle.main.object(forInfoDictionaryKey: kCFBundleVersionKey as String) as! String
или в Objective-C
NSString * version = [[NSBundle mainBundle] objectForInfoDictionaryKey: @"CFBundleShortVersionString"];
NSString * build = [[NSBundle mainBundle] objectForInfoDictionaryKey: (NSString *)kCFBundleVersionKey];
У меня есть следующие методы в категории на UIApplication
:
extension UIApplication {
class func appVersion() -> String {
return Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString") as! String
}
class func appBuild() -> String {
return Bundle.main.object(forInfoDictionaryKey: kCFBundleVersionKey as String) as! String
}
class func versionBuild() -> String {
let version = appVersion(), build = appBuild()
return version == build ? "v\(version)" : "v\(version)(\(build))"
}
}
Суть: https://gist.github.com/ashleymills/6ec9fce6d7ec2a11af9b
Вот эквивалент в Objective-C:
+ (NSString *) appVersion
{
return [[NSBundle mainBundle] objectForInfoDictionaryKey: @"CFBundleShortVersionString"];
}
+ (NSString *) build
{
return [[NSBundle mainBundle] objectForInfoDictionaryKey: (NSString *)kCFBundleVersionKey];
}
+ (NSString *) versionBuild
{
NSString * version = [self appVersion];
NSString * build = [self build];
NSString * versionBuild = [NSString stringWithFormat: @"v%@", version];
if (![version isEqualToString: build]) {
versionBuild = [NSString stringWithFormat: @"%@(%@)", versionBuild, build];
}
return versionBuild;
}
Суть: https://gist.github.com/ashleymills/c37efb46c9dbef73d5dd