When exactly are the settings from Apple’s Settings app saved?
The main interface of my app depends on some of the settings that can be set by the user in Apple's Settings app.
If the user switches from my app to the Settings app and changes some settings, I try to get them in the applicationWillEnterFor开发者_StackOverfloweground:application method in my delegate by using [[NSUserDefaults standardUserDefaults] valueForKey:@"someSetting"]. However at that point I still get the old settings value. Later on if I read the setting value it's already correct.
When exactly are the settings from Apple’s Settings app saved? Any other approaches to achieve the same goal?
I don't think you need to read the NSUserDefaults in applicationWillEnterForeground:application
, since the application was not terminated if you get back to the foreground, so all of your settings are still there.
Apart form this, it is my understanding the HSUserDefaults
are stored when the application is closed or when you call the synchronize
method.
THe best approach, considering that you application could be terminated while in the background is, IMO, call synchronize
in your applicationWillEnterBackground`. Then, if you like, you can read them back (but it should not be necessary, as I said earlier) when you enter foreground again.
You will need to read them when your applicationFinishedLaunching.
精彩评论