2

Is it possible to access the app version that I specify in the xcode project setting from within the application?

I'm trying to create an auto-updating "About" view controller, and it would be nice to receive bug reports listing the version of the app.

I know this can be done with built-in constant, but I'm wandering if there's a better way.

Thank you!

Alex Stone
  • 46,408
  • 55
  • 231
  • 407

2 Answers2

3

You can read you Info.plist in your main bundle for the according key.

Sample code:

NSBundle     *bundle    = [NSBundle mainBundle];
NSString     *infosPath = [bundle pathForResource:@"Info" ofType:@"plist"];
NSDictionary *infosDict = [[NSDictionary alloc] initWithContentsOfFile:infosPath];

NSLog(@"CFBundleVersion : %@" , [infosDict valueForKey:@"CFBundleVersion"]);

I just tested this code and its working fine. Do a right-clik on you Info.plist to display raw key names.

Also, I was testing this code with a plist with spaces in its names, which gave me 'null' for the infosPath. Deleting the space solves the problem.

teriiehina
  • 4,741
  • 3
  • 41
  • 63
1

This is how I can get the version number that has to be incremented for App store upload:

NSString* version = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];
Alex Stone
  • 46,408
  • 55
  • 231
  • 407