I'm running into something a bit puzzling. I have some basic string data that I'm trying to save to the NSUserDefaults, like so:
NSString *state = @"finished";
[[NSUserDefaults standardUserDefaults] setObject:state forKey:@"downloadFinished"];
[[NSUserDefaults standardUserDefaults] synchronize];
When the app starts, one of the ways it makes decisions on which view to load is to check the value of this user setting:
NSString *savedState = [[NSUserDefaults standardUserDefaults] stringForKey:@"downloadFinished"]
if(savedState && [savedState length]) {
// Show view
}
Every once in a while, I've noticed that this value fails to load, even though I know for sure that this value was saved previously (or at least, the app tried to save it previously). When this happens, I'm getting a nil value back when I lookup the "downloadFinished" key from the user defaults.
Has anyone run into this before? Is there any knowledge out there on why this might happen? How likely is it that the save to the user's defaults cache and defaults database fails, and is there anyway to further prevent this from happening?
I'm going to try the solution mentioned in Why is NSUserDefaults not saving my values?, which forces another synchronize when the app enters the background, but I'm wondering if anyone has deeper knowledge on the matter.