There are many answers related to using registering user defaults, and I looked hard, and I am still shocked by the behavior that I see.
In my set of settings, I have one toggle switch that I give the identifier 'sharing', giving it the default value of YES. I see this switch in the settings application, but it is not enabled by default. Even if I remove the application from the phone and reinstall it.
In my prefinishlaunchingwithoptions method, I have the following:
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; NSDictionary *appDefaults = [NSDictionary dictionaryWithObject:@"YES" forKey:@"sharing"]; [defaults registerDefaults:appDefaults]; [defaults synchronize];
If I check that:
NSLog(@"%d",[defaults boolForKey:@"sharing"]);
The default value is set, but it is not reflected in the settings application.
If I then go to the settings app and turn on the switch and turn it on and check the value:
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; BOOL enabled = [defaults boolForKey:@"sharing"];
This will still result in the YES I expect.
And then I flip it back and test again:
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; BOOL enabled = [defaults boolForKey:@"sharing"];
It will be NO, as expected, and now the connection works just fine.
So, basically everything works fine, except that until the default setting is changed, it exists programmatically, but does not appear visually in the settings application.
Hope someone can point out what I am missing!
thanks