We are developing an iPhone application. The app is available in the app store. We are using NSUserDefaults to store our usertoken value. But some users reports that the usertoken is became null when the app idle (in background) for long time. But normally the value is getting.
The following is the code for storing usertoken in the NSUserDefaults. We are setting the value to the userToken from the login page and signup pages.
[[NSUserDefaults standardUserDefaults] setObject:userToken forKey:USER_TOEKN];
I have not called synchronize after setting value to NSUserDefaults. Could you please help
You need to call
[[NSUserDefaults standardUserDefaults] synchronize];if your app is going to be backgrounded – my guess is the app idles before the defaults automatically synchronizes. From the documentation:As for where to do this, take a look at applicationWillResignActive: and applicationDidEnterBackground: in your Application Delegate.