Accessing Info.plist within your iPhone App

I needed to access the app name w/in my app. I figured I cd get it from the Info.plist display name or executable. Yep.

See all the values w/ this (print out below)…

[code]
NSLog(@"%@", [[NSBundle mainBundle] infoDictionary]);
[/code]

Or get a single value w/ this…

[code]
NSString *exeName = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleName"];
[/code]

You can get the dictionary key names from the plist file in Xcode. Just set the view to show the raw key names…

Set Raw Key Names in Xcode (click to enlarge)

Set Raw Key Names in Xcode (click to enlarge)

The raw key names…

Raw Key Names (click to enlarge)

Raw Key Names (click to enlarge)

Print out the dictionary…

[code]
2009-12-30 10:52:09.948 MyApp [32400:207] {
CFBundleDevelopmentRegion = English;
CFBundleDisplayName = MyApp;
CFBundleExecutable = MyApp;
CFBundleExecutablePath = "/Users/bear/Library/Application Support/iPhone Simulator/User/Applications/722BFAB7-9A59-4282-A0EF-BD5675B44FE8/MyApp.app/MyApp";
CFBundleIdentifier = "com.yourcompany.MyApp";
CFBundleInfoDictionaryVersion = "6.0";
CFBundleInfoPlistURL = Info.plist — file://localhost/Users/bear/Library/Application%20Support/iPhone%20Simulator/User/Applications/722BFAB7-9A59-4282-A0EF-BD5675B44FE8/MyApp.app/;
CFBundleName = MyApp;
CFBundlePackageType = APPL;
CFBundleSignature = "????";
CFBundleSupportedPlatforms = (
iPhoneSimulator
);
CFBundleVersion = "1.0";
DTPlatformName = iphonesimulator;
DTSDKName = "iphonesimulator3.1.2";
LSRequiresIPhoneOS = 1;
NSBundleInitialPath = "/Users/bear/Library/Application Support/iPhone Simulator/User/Applications/722BFAB7-9A59-4282-A0EF-BD5675B44FE8/MyApp.app";
NSBundleResolvedPath = "/Users/bear/Library/Application Support/iPhone Simulator/User/Applications/722BFAB7-9A59-4282-A0EF-BD5675B44FE8/MyApp.app";
NSMainNibFile = MainWindow;
}

[/code]