Read the version from Info.plist

I want to read package version information from Info.plist into my code, preferably as a string. How can i do this?

+83
objective-c iphone cocoa-touch xcode info.plist
Oct 30 '10 at 14:25
source share
5 answers

You can read your Info.plist as a dictionary using

[[NSBundle mainBundle] infoDictionary] 

And you can easily get the version with the CFBundleVersion key this way.

Finally, you can get the version with

 NSDictionary* infoDict = [[NSBundle mainBundle] infoDictionary]; NSString* version = [infoDict objectForKey:@"CFBundleVersion"]; 
+190
Oct 30 2018-10-10
source share

for Swift users:

 if let version = NSBundle.mainBundle().objectForInfoDictionaryKey("CFBundleShortVersionString") { print("version is : \(version)") } 

for Swift3 users:

 if let version = Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString") { print("version is : \(version)") } 
+5
Oct 24 '15 at 18:03
source share

I know that some time has passed after the quest and the answer.

Since iOS8 accepted answer may not work.

This is a new way to do it now:

 NSString *version = (__bridge id)CFBundleGetValueForInfoDictionaryKey(CFBundleGetMainBundle(), kCFBundleVersionKey); 
+4
Jun 25 '14 at 11:09
source share

IOS 8 now requires both fields. Previously, it works without CFBundleShortVersionString . But now this is a required plist field for sending any application to the application store. And kCFBundleVersionKey compared to load each new assembly, which should be in ascending order. Especially for the assembly of TestFlight. I do it this way

 NSString * version = nil; version = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"]; if (!version) { version = [[NSBundle mainBundle] objectForInfoDictionaryKey:(NSString *)kCFBundleVersionKey]; } 
+3
Oct 21 '14 at 11:30
source share

Swift 3:

 let appBuildNumber = Bundle.main.infoDictionary!["CFBundleVersion"] as! String let appVersion = Bundle.main.infoDictionary!["CFBundleShortVersionString"] as! String 
+2
Jun 30 '17 at 3:02
source share



All Articles