I want to read the bundle version info from Info.plist into my code, preferably as a string. How can I do this?
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.
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.
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.
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"];
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)") }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With