I am working on a Universal app & would like to access the values stored in app-info.plist file in my code.
Reason: I instantiate a UIViewController dynamically from a storyboard using:
UIStoryboard* storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone" bundle:nil]; self = [storyboard instantiateViewControllerWithIdentifier:@"ExampleViewController"];
Now, having the storyboard name @"MainStoryboard_iPhone" above is ugly.
I want to do something like:
UIStoryboard* storyboard = [UIStoryboard storyboardWithName:appInfo.mainStoryboardBaseNamePhone bundle:nil]; self = [storyboard instantiateViewControllerWithIdentifier:@"ExampleViewController"];
where appInfo can perhaps be an NSDictionary of all values in app-info.plist
Press ⌘+⇧+o to get the Quick Open Dialog. Enter name of property list file e.g. " info. plist " and press "Enter" Open "Version Editor" -> Property List File is shown as source code.
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.
All you have to do is click on the blue project icon -on top of the left- and go to the “Build Settings” tab, search “Info. plist” and choose “Info. plist File” section. Then change the information of the section from your folder's name.
Attributes from the info.plist for your project are directly accessible by the following...
[[NSBundle mainBundle] objectForInfoDictionaryKey:key_name];
For example to get the version number you might do the following
NSString *appVersion = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"];
There is a gotcha in that the version number now has two attributes in the info.plist - but you get the idea? If you view your info.plist as source code (right click the info.plist - select Open As) then you will get to see all the various key names you can use.
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