NSUserDefaults appears to be corrupt or missing after appstore=>testflight update.

Currently, my application is experiancing a strange couruption and crashing behavior in the NSUserDefaults subsystem.

We believe we are using the api correctly, but notice that after updating our application from the current, older App Store version, to our working HEAD version, every key that our application sets in the defaults is either “corrupted", or missing entirely. This behavior seems to vary based on physical device, but seems to be consistent across installs. (That is, if one user experiences missing data after updating, they always experience that behavior. If another user experiences corrupt behavior, they always experience that behavior.)

By corruption, we mean that NSUserDefaults ought to return a verity of data types corresponding to the type of data entered. Instead, strange data (

_NSCFData
) blobs are being returned.

We believe we’ve been able to isolate this issue to be occurring strictly outside of our own code base. Placing a breakpoint right before the call to

UIApplicationMain()
and have used lldb to print out:
po [[NSUserDefaults standardUserDefaults] dictionaryRepresentation]

Which yields the usual apple keys, and our own entries which look like:

KeyName = <f475198e ac5618c4 e0bc14a3 856fa068 10597406 .... >


This seems very unusual and guidance would be much appreciated.

Replies

I also experienced UserDefaults data wiping out on upgrade from an Appstore version to a TestFlight version and it's ok according to answer on StackOverflow:
"as you probably know that via TestFlight there is no such thing "update", the TestFlight always does a clean install for security reason, regardless an earlier version of the app was/wasn't already on the device – and that includes to clean the

NSUserDefault
as well."
https://stackoverflow.com/questions/35196228/nsuserdefaults-gets-cleared-when-app-updates