jcardenete jcardenete - 1 year ago 113
iOS Question

iOS app, programmatically get build version

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

Answer Source

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


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


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

and the "Build":


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


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