How to get CFBundleVersion in info.plist
‘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.