Josh Schumacher: A PHP Developer

The biggest and the best in the Northwest

Josh Schumacher: A PHP Developer random header image

Reading Common and Custom Values From Your Info.plist

February 19th, 2009 · 1 Comment

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

CODE:
  1. // Create a new NSBundle pointer
  2. NSBundle* mainBundle;
  3.  
  4. // The Info.plist is considered the mainBundle.
  5. mainBundle = [NSBundle mainBundle]
  6.  
  7. // Reads the value of the custom key I added to the Info.plist
  8. [mainBundle objectForInfoDictionaryKey:@"myCustomKey"]
  9.  
  10. // Another handy thing I had to search around for a little
  11. // Get the value for the "Bundle version" from the Info.plist
  12. [mainBundle objectForInfoDictionaryKey:@"CFBundleVersion"]
  13.  
  14. // Need the bundle identifier? (probably something like com.mycorp.product)
  15. [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.

Tags: Objective-C · iPhone Development · iPhone SDK

1 response so far ↓

  • 1 Vishal Sharma // Oct 16, 2009 at 8:21 pm

    THx Buddy for ur valuable Code

Leave a Comment