Read info.plist Key-Value Pairs

Tue, Oct 16

You can read standard (Apple defined) key-value pairs from the info.plist file in your iOS app, as well as read any custom entries you have defined. This applies to all data types stored in the plist, that is strings, arrays, etc.

For example, assume you have the following in your info.plist:


PreferencesSet is a custom defined value I created, CFBundleVersion and CFBundleURLTypes are pre-defined by Apple.

To read the values is as simple as:

NSNumber *prefSet = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"PreferencesSet"];
NSLog(@"PreferencesSet: %@", prefSet);
 
NSString *version = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"];
NSLog(@"CFBundleVersion: %@", version);
 
NSArray *customURL = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleURLTypes"];
debug(@"Custom URL: %@", customURL);

The output follows:

PreferencesSet: 0
CFBundleVersion: 1.1
Custom URL: (
{
CFBundleURLName = “com.myCompany.testapp”;
CFBundleURLSchemes = (
MyAppURL
);
}
)

Leave a Comment