Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 471
jcardenete Avatar asked Oct 15 '22 02:10

jcardenete


People also ask

What is CFBundleShortVersionString?

CFBundleShortVersionString gives you the version of your app. It's typically incremented each time you publish your app to the App Store. This is the version that is visible on the "Version" section for the App Store page of your application.


1 Answers

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

Swift 3

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

ObjC

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

Swift 2

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

and the "Build":

Swift 3

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

ObjC

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

Swift 2

let build = NSBundle.mainBundle().infoDictionary?[kCFBundleVersionKey as String] as! String
like image 297
e1985 Avatar answered Oct 16 '22 14:10

e1985