Home > Programming > How to get CFBundleVersion in info.plist

How to get CFBundleVersion in info.plist

February 21st, 2009 Leave a comment Go to comments

‘info.plist’ file in XCode iPhone or Mac OS X project contains essential information about the project.

We can extract information in ‘info.plist’ in our program to utilize them in our code. Let me explain how to retrieve/utilize CFBundleVersion in info.plist as example.

I got very sophisticated code flagment by comment. Thanks kl!

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

CFBundleRef mainBundle = CFBundleGetMainBundle();
int ver = CFBundleGetVersionNumber(mainBundle);
int ver0 = (ver & 0xf0000000) >> 28;
int ver1 = (ver & 0x0f000000) >> 24;
int ver2 = (ver & 0x00f00000) >> 20;
NSString version = [NSString stringWithFormat:@"v%i%i.%i", ver0, ver1, ver2];

Note: int value ‘ver’ contains BCD encoded version number. So, we need to separate it by 4 bits boundary.

Categories: Programming Tags:
  1. June 30th, 2009 at 05:53 | #1

    [[[NSBundle mainBundle] infoDictionary] objectForKey:@”CFBundleGetInfoString”]

    Much easier! (and no carbon stuff)

  2. admin
    June 30th, 2009 at 12:41 | #2

    Wow, thank you very much! I will rewrite the entry.

  3. November 19th, 2009 at 21:01 | #3

    you just saved my day ;)

  4. February 2nd, 2011 at 07:55 | #4

    Yes, thanks for this!

  1. No trackbacks yet.