Changes to Application Preferences not Saving or Not Immediately Available?
I've successfully created my application's Settings.bundle and the items I need within it. I can open the panel in the Settings app, change values, exit the Settings app go back in and confirm they are as I left them.
I launch my app and read those preferences, I don't see the changes - not after the first launch.
However, if I exit my app and launch it again I see the changes!
My plist is set up like so...
Type: PSToggleSwitchSpecifier (String) Key: EmailOnMessage (String) Title: EmailOnMessageTitle (String) DefaultValue: YES (Boolean) TrueValue: 1 (Number) FalseValue: 0 (Number)
I'm reading the preference开发者_运维问答s per Apple's docs...
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults integerForKey:@"EmailOnMessage"];
And I'm doing this in the applicationDidBecomeActive method in my AppDelegate.
Why would my app not be seeing the updates here? Are those setting not synchronized until further down the app lifecycle? If so, where?
The NSUserDefaults is not synchronized after each changes. It may be synchronized at periodic interval by the system, but if you want to use the new values right-away, you have to explicitly call the synchronize
method.
精彩评论