开发者

The default user settings stored in NSUserSettings don't seem to load

So I have a settings bundle in my iPhone app and my probl开发者_StackOverflow中文版em is that the values for the UISwitches that have default values of "enabled" are not being read from the settings bundle the first time the app is installed on a phone.

In order for the default settings to register I need to go into the iphone settings and simply view/load the settings page for my app, so that the settings get "Set". What is going on here???

Recap: I need to go into the settings app on the iPhone and simply view/load the page for my app in order for the default values to get registered into the NSUserDefaults, but I need them to load the first time the app is installed, and not on the condition that the user must go into the settings and view the page.

This is how i'm loading my settings in the viewDidLoad method:

[[NSUserDefaults standardUserDefaults] synchronize];
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];

if (([[defaults objectForKey:kToggleSwitch] isEqualToString:@"Enabled"]) ? YES : NO) {
//Do Stuff
}

P.S. I could simply set all the switches to Disabled/False values but for my app it would be preferable having certain switches on and others off.


add - (void)registerDefaults:(NSDictionary *)dictionary to one of the methods called at application startup. You have to register your defaults at every start.
NSUserDefaults Documentation

Btw. there is boolForKey:, and setBool:ForKey:, no need to compare strings.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜