jcardenete jcardenete - 6 months ago 37
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

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

ObjC

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

Swift

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

and the "Build":

ObjC

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

Swift

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