Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Read version from Info.plist

I want to read the bundle version info from Info.plist into my code, preferably as a string. How can I do this?

like image 233
John Smith Avatar asked Oct 30 '10 14:10

John Smith


People also ask

How do I read a plist file on a Mac?

plist - The primary property list for Mac OS X applications, located in the /​Contents/​ directory of an . APP bundle. To view this file, right-click an application file, select "Show Package Contents," and open the Contents folder.

How do I access plist?

In Xcode you can see a plist's XML structure by right-clicking on a . plist file, and choosing Open As → Source Code. If you look closely, you can spot the different values and structures in the XML.

What is in Info plist?

The Info. plist file contains critical information about the configuration of an iOS mobile app—such as iOS versions that are supported and device compatibility—which the operating system uses to interact with the app. This file is automatically created when the mobile app is compiled.


2 Answers

You can read your Info.plist as a dictionary with

[[NSBundle mainBundle] infoDictionary] 

And you can easily get the version at the CFBundleVersion key that way.

Finally, you can get the version with

NSDictionary* infoDict = [[NSBundle mainBundle] infoDictionary]; NSString* version = [infoDict objectForKey:@"CFBundleVersion"]; 
like image 96
gcamp Avatar answered Sep 28 '22 13:09

gcamp


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)") } 
like image 37
ayalcinkaya Avatar answered Sep 28 '22 11:09

ayalcinkaya