Reputation: 1177
In Xcode 6: NSUserDefaults
does not work in devices simulators (iPhone 5, iPhone 6, etc, simulators).
If you test on real devices, it works perfect. Someone know how to send this information to Apple? I have tried to contact Apple, but I have not received answer.
I can not test on a real iPhone6 or iPhone6 Plus because in my country is not yet available.
My code (is an example) that works perfect on devices:
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSString *appTheme = [defaults objectForKey:@"theme_preference"];
if ([appTheme isEqualToString:@"color0"]) {
} else {
}
Probably, I did not expressed myself clearly.
The user, in "iPhone o iPad Settings" must change the settings parameters of the application.
The settings are implemented by the "Root.plist" of the "Settings.bundle".
That is, I try to test the user changes the parameters of the application. But in the source code I do not see these changes. I talk always of devices simulators (Xcode6)
Upvotes: 7
Views: 1769
Reputation: 9
Go to the iOS simulator in the menu and then click reset content settings, now your problem should be solved.
Upvotes: 0
Reputation: 1177
Today I finally have fixed the problem. I have installed the latest update of Xcode (Version 6.1) and then I have reset the simulator.
Then I have accessed to my settings App. Until you open the settings of your application, settings are not copied in simulator (or real device)
It is imperative access at least once to your App settings.
Upvotes: 2
Reputation: 3491
It is a bug of iOS simulator, you should go to iOS Simulator > Reset Content and Settings to reset device.
Upvotes: 0
Reputation: 3914
This is a common problem now with xCode6 and ios8.
What I found is to Reset simulator content and settings whenever you face this issue of NSUserDefaults.
when I deleted the app from simulator, the values of userdefaults were not cleared.
Then I Reset my simulator and it worked fine for me.
So as of now until apple gives a fix for this, the best way to test on simulator is to reset simulator whenever you want to delete the app.
It worked for me. Hope it helps someone else also.
Upvotes: 0
Reputation: 610
Try to save data like this:
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:@"color0" forKey:@"theme_preference"];
[defaults synchronize];
And then call it later :
NSString *appTheme = [defaults objectForKey:@"theme_preference"];
if ([appTheme isEqualToString:@"color0"]) {
} else {
}
Upvotes: 0