Zurück zur Übersicht

David Linsin

16.08.2010

Settings Bundle and Default Values

I Think I Spider


<key>Type</key>
<string>PSToggleSwitchSpecifier</string>
<key>Title</key>
<string>Sound</string>
<key>Key</key>
<string>sound_enabled</string>
<key>DefaultValue</key>
<true/>

Unfortuntately, the default value is only applied the first time you access the Settings Application. That means your code cannot rely on the default values and rather has to check manually, if the value has been set in the Settings Application. In case of “I think I spider”, that meant no sound until you accessed the Settings Application. After poking around for a couple of minutes, we found a workaround, which we implemented in our AppDelegate’s didFinishLaunchingWithOptions method:


id test = [[NSUserDefaults standardUserDefaults] objectForKey:@"sound_enabled"];
if (test == NULL) {
    [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"sound_enabled"];
}
return YES;

This checks if no value was set, which means the returned value is NULL, and in that case sets our default value. Note that we are duplicating the default value definition here. You could also access the Settings Bundle programmatically and read the default value from there.

This gives us an easy workaround, so that you can enjoy the awesome sound effects in “I think I spider”.