Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to display the current project version of my App to the user?

I would like to add the current version into the "about" section of my app. As seen in this attached screenshot Apple offers versioning.

How do you display these settings in your app?

Screenshot of Target 'myApp' Info

like image 869
jantimon Avatar asked Sep 29 '09 12:09

jantimon


2 Answers

After further searching and testing, I found the solution myself.

NSDictionary* infoDictionary = [[NSBundle mainBundle] infoDictionary];
NSLog(@"%i Keys:  %@", [infoDictionary count],
             [[infoDictionary allKeys] componentsJoinedByString: @" ,"]);

This snipplet gave me the following output:

20 Keys : NSBundleResolvedPath ,CFBundleVersion ,NSBundleInitialPath ,CFBundleIdentifier ,NSMainNibFile ,CFBundleIconFile ,CFBundleInfoPlistURL ,CFBundleExecutable ,DTSDKName ,UIStatusBarStyle ,CFBundleDevelopmentRegion ,DTPlatformName ,CFBundleInfoDictionaryVersion ,CFBundleSupportedPlatforms ,CFBundleExecutablePath ,CFBundleDisplayName ,LSRequiresIPhoneOS ,CFBundlePackageType ,CFBundleSignature ,CFBundleName

So the solution is as simple as:

NSString *version =[[[NSBundle mainBundle] infoDictionary] valueForKey:@"CFBundleVersion"];

However, this is not the Current Project Version as seen in the screenshot but the Bundle Version of the plist file.

like image 139
jantimon Avatar answered Sep 21 '22 09:09

jantimon


Look into your Info.plist file which should have keys like CFBundleVersion and CFBundleShortVersionString

like image 33
Eimantas Avatar answered Sep 21 '22 09:09

Eimantas