Settings Bundle and Default Values
We improved our “I think I spider” App quite a bit since Beta 1. Among other stuff we added some nice sound effects. If you want to check it out, let us know and we’ll hook you up!
If you are like me and not a big fan of sounds, you probably want to turn them off. That’s why we provide a Settings Bundle, which lets you flip a switch in the Settings Application of your iOS device, in order to turn off sounds.
While implementing this feature, we ran into some pitfall with Settings Bundle’s default values. You can define default values in the appropriate Root.plist, like this:
<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”.