iPhone settings not honoured
        Posted  
        
            by winsmith
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by winsmith
        
        
        
        Published on 2010-05-16T12:20:28Z
        Indexed on 
            2010/05/16
            12:30 UTC
        
        
        Read the original article
        Hit count: 216
        
iphone-sdk
|nsuserdefaults
My iPhone app has the following problem: Freshly installed, when I read out my "Play Sound" preference with the following code:
defaults = [NSUserDefaults standardUserDefaults];
NSLog(@"Play Sounds? %d", [defaults boolForKey:@"play_sounds_preference"]);
The setting always reads out as false, even though the default setting is set to true. Any ideas? Here is my Root.plist:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>StringsTable</key>
    <string>Root</string>
    <key>PreferenceSpecifiers</key>
    <array>
        <dict>
            <key>Type</key>
            <string>PSGroupSpecifier</string>
            <key>Title</key>
                <string>General Settings</string>
            </dict>
            <dict>
                <key>Type</key>
                    <string>PSToggleSwitchSpecifier</string>
                    <key>Title</key>
                    <string>Sounds</string>
                    <key>Key</key>
                    <string>play_sounds_preference</string>
                    <key>DefaultValue</key>
                    <true/>
            </dict>
    </array>
</dict>
</plist>
When the user opens the Settings.app and navigates to my app's name, THEN the setting reads out as true, even if the user doesn't change anything.
© Stack Overflow or respective owner