Reputation: 10794
Cleaning an app's NSUserDefaults
after the app has been uninstalled. Conversely, on re-install of an app, having it ignore any previous NSUserDefaults that might have been stored. That is, being able to detect that those NSUserDefaults belong to an earlier install that was since uninstalled.
Note that the uninstalled and re-installed version could be the exact same build/version number.
I'm storing some key-value pairs that represent timestamps for the load of specific reference data files, so the my app can simply skip re-loading reference data that hasn't changed.
During development, I sometimes remove the app from the simulator or device, but don't want to have to reset all settings to clear out NSUserDefaults
.
I realize there are a host of things I can put in place to determine if my reference data load is complete and up to date. My goal is to determine whether between installs / uninstalls of my app, this fact can easily be determined.
Once reference data is installed (loaded), that's not the end of the story, as new patches will exist and based on their timestamp, I'll need to determine whether to ignore or whether to do an update-or-create style import.
Upvotes: 1
Views: 641
Reputation: 179
The NSUserDefaults are cleared automatically when the app is uninstalled, they never persist if you uninstall the app. So you don't need anything to detect that the app is uninstalled the NSUserDefaults would be empty when you reinstall the app.
If you want values to persist between app installation you can use the KeyChain.
Upvotes: 1
Reputation: 10794
Instead of using NSUserDefaults
, an app can just read/write it's own property list file that will get blown away with an uninstall.
We can store a timestamp in that property list for first launch, so that an app can determine when this current install was applied. The same key in the NSUserDefaults
database would represent the first install of the app ever. Two similar, but distinct bits of information.
Combining the two, we can then store a count in the NSUserDefaults of how many times an app has been completely re-installed, if we wanted to know.
Aside: writing out a problem certainly does help clarify an issue in one's own mind!
Upvotes: 0