It seems like a pretty simple, common thing you would want to do in objective-c right? All applications have an Info.plist (or a different plist file as defined in your "Info.plist File" property of your build target). I've been pretty frustrated with the quality of google search results when trying to figure out how to do more or less mundane things with the iPhone SDK. I'm going to start writting posts, especially when I have a hard time trying to find what I was looking for in search results.
Here's the quick and dirty: I have a game that we're building here at Treemo Labs, Tic A Tac Poker. We're working on getting a lite version out the door. I wanted to read a custom value out of the Info.plist to tell if it's the lite version or not. I couldn't figure out how to read a simple value from the default property list file. Here's some sample code to get the bundleIdentifier, bundle version and custom values from your Info.plist
-
// Create a new NSBundle pointer
-
NSBundle* mainBundle;
-
-
// The Info.plist is considered the mainBundle.
-
mainBundle = [NSBundle mainBundle];
-
-
// Reads the value of the custom key I added to the Info.plist
-
[mainBundle objectForInfoDictionaryKey:@"myCustomKey"]
-
-
// Another handy thing I had to search around for a little
-
// Get the value for the "Bundle version" from the Info.plist
-
[mainBundle objectForInfoDictionaryKey:@"CFBundleVersion"]
-
-
// Need the bundle identifier? (probably something like com.mycorp.product)
-
[mainBundle bundleIdentifier]
For more information about the NSBundle, view the NSBundle Reference Documentation.
To see an alphabetical list of the standard keys you can use in an information property list file, along with a brief description and the platforms to which they apply (Mac OS X or iPhone) check out the Property List Key Reference.







1 response so far ↓
1 Vishal Sharma // Oct 16, 2009 at 8:21 pm
THx Buddy for ur valuable Code
Leave a Comment