I have an iOS application with a settings.bundle that handles various settings for my application with Switch toggle
. I set default values in my root.plist file (using the DefaultValue property) to YES
but any time the application launches on a device or the iOS simulator all values go NO
. It worked well only on the first launch.
I am retrieving the defaults with this code (am I doing something wrong here?):
NSUserDefaults *localeDefaults = [NSUserDefaults standardUserDefaults];
BOOL ENWORDS = [localeDefaults boolForKey:@"localetime"];
The Default Value is used by Settings.app for display purposes only. If you don't change the value in the settings app nothing is saved to NSUserDefaults.
You have to register the default values yourself. Use something like this in application:didFinishLaunchingWithOptions:
:
NSDictionary *userDefaultsDefaults = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithBool:YES], @"localetime",
nil];
[[NSUserDefaults standardUserDefaults] registerDefaults:userDefaultsDefaults];