-
Re: Various iOS apps log out randomly, lose all data & settings
elementarteilchen Jan 24, 2017 2:12 PM (in response to JorgeFlor)This issue exists for about a year now (it seems that this bug was introduced in iOS 9.3.1 and is still present in iOS 10.2).
The problem seems to be that after an App is launched and tries to load its settings from NSUserDefaults, it does not get any data. It looks like NSUserDefaults sometimes "forgets" to load its data from the file system. If you manage to kill the App before it tries to store new data in NSUserDefaults and the restart the App, chances are good that this time NSUSerDefaults does load the data correctly and the App can get all its settings again. But as soon as the App stores anything in NSUserDefaults, all old data is overwritten and lost forever.
But killing an App before it can store anything in NSUserDefaults is usually only possible for your own Apps when running them in the debugger.
There are a lot of threads here in the developer forums related to this topic. We all hope that Apple will someday find and fix this annoying bug. Even though with some luck the issue won't show up very often, it is nevertheless very annoying. Please send bug reports to Apple, so Apple learns that this is serious.
Here are a few other related threads:
https://forums.developer.apple.com/thread/44264
https://forums.developer.apple.com/thread/44685
-
Re: Various iOS apps log out randomly, lose all data & settings
nailer Jan 25, 2017 7:29 AM (in response to JorgeFlor)Hm, I'm currently furiously looking for the reason users in our app is being logged out. I use NSUserDefaults with encryption to store the authentication token. For some reason, after our last update, users are logged out en masse. We have barely changed the code at all. And surely nothing considering the saving of the token. My initial fear was that [[UIDevice currentDevice]identifierForVendor] had changed after update. I've found bugs on that reported previously.
-
Re: Various iOS apps log out randomly, lose all data & settings
LluisGerard Feb 16, 2017 5:51 AM (in response to nailer)Might be a little off topic but is better not to use UserDefaults to store tokens. Use Keychain instead. As explained in this example from Apple https://developer.apple.com/library/content/samplecode/GenericKeychain/Introduction/Intro.html
-
-
Re: Various iOS apps log out randomly, lose all data & settings
richterd Feb 11, 2017 12:13 AM (in response to JorgeFlor)Hi, I have the same issue since I started developing for/on the iPhone with a second Mac and a second Apple ID...
-
Re: Various iOS apps log out randomly, lose all data & settings
jmajsty Mar 27, 2017 1:46 PM (in response to JorgeFlor)I have encountered this in development. I found that I can access the keys that should be there by inserting a random value into NSUserDefaults and checking again.
BOOL seen = [[NSUserDefaults sharedUserDefaults] objectForKey:MY_KEY] != nil;
if (!seen) {
// are you sure? try again...
[[NSUserDefaults sharedUserDefaults] setObject:[NSUUID UUID].UUIDString
forKey:@"TEMP_KEY"];
seen = [[NSUserDefaults sharedUserDefaults] objectForKey:MY_KEY] != nil;
}
return seen;