nsuserdefaults - iPhone settings not honoured -


In my iPhone app, there is a problem with the following: When I installed my "Play sound" priority with the following code Read:

default = [NSUserDefaults Standard User Defaults]; NSLog (@ "Play Sound?% D", [OUT BULL FORACHI: @ "PLAY_SSOLS_change"]);

The setting always reads as false, even if the default setting is set to true. any idea? Here's my root. Plist:

  & lt ;? Xml version = "1.0" encoding = "UTF-8"? & Gt; & Lt ;! DOCTYPE plist PUBLIC "- // Apple // DTD PLIST 1.0 // n" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> & Lt; Plist version = "1.0" & gt; & Lt; Dict & gt; & Lt; Key & gt; StringsTable & lt; / Key & gt; & Lt; String & gt; Root & lt; / String & gt; & Lt; Key & gt; PreferenceSpecifiers & lt; / Key & gt; & Lt; Array & gt; & Lt; Dict & gt; & Lt; Key & gt; & Lt; / Key & gt; & Lt; String & gt; PSGroupSpecifier & lt; / String & gt; & Lt; Key & gt; Title & lt; / Key & gt; & Lt; String & gt; General settings & lt; / String & gt; & Lt; / Dict & gt; & Lt; Dict & gt; & Lt; Key & gt; & Lt; / Key & gt; & Lt; String & gt; PSToggleSwitchSpecifier & lt; / String & gt; & Lt; Key & gt; Title & lt; / Key & gt; & Lt; String & gt; Sound & lt; / String & gt; & Lt; Key & gt; Key & lt; / Key & gt; & Lt; String & gt; Play_sounds_preference & lt; / String & gt; & Lt; Key & gt; DefaultValue & lt; / Key & gt; & Lt; True /> & Lt; / Dict & gt; & Lt; / Array & gt; & Lt; / Dict & gt; & Lt; / Plist & gt;  

When the user opens the Settings app and navigates to the name of my app, then reads the settings as correct, even if the user does not change anything.

The default setting is set only when the user opens the settings app, unfortunately.

You can simply check that the key is present when you start the app, and if it does not:

  if (! [NSUserDefaults standard user Default] ObjectForcae: @ "The Keke"]) [[NSUASER Default StandardUserDefaults] setBool: Yes for Key: @ "theKey"]; }  

Or, if you have many keys that require setting, then you can see the register of NSUserDefault at default.


Comments