views:

308

answers:

2

Hi,

Is this the case? Do NSUserDefaults get reset when you submit an update to an app on the App Store, or are they reset?

My app is crashing when updated but not crashing when downloaded fully - so I'm trying to determine what could possibly be different in the updated session to the freshly downloaded session.

Cheers, Nick.

+3  A: 

They are usually not reset unless the user deletes the app. To save state, NSUserDefaults is the way to go. I believe most, if not all, instances of application data being deleted after an upgrade are due to issues on the AppStore. They may be related to data-format changes, but if you use just NSUserDefaults and standard plist-storable objects (NSString, NSDictionary, NSNumber, NSArray, NSNumber, and primitives), you should be safe.

coneybeare
Is there somewhere in the Apple documentation this is mentioned?
Nick Cartwright
Sorry - I forgot to thank you for your quick answer! - If anyone can find a link to any form of Apple documentation that says this, It would be excellent.... In the documentation for NSUserDefaults it says nothing about this, so I think I had (incorrectly) assumed the defaults get wiped. This would seem the safest way for Apple to update apps surely!
Nick Cartwright
It might be the safest way, but it would be incredibly annoying for users if they had to re-set all their preferences whenever an app got updated. I generally have three or four app updates per day; I'm sure other iPhone users have even more. Wiping preferences for each update would basically make my iPhone unusable.
Kristopher Johnson
Data in the documents folder can disappear just as easily as the NSUserDefaults. They are both rare occasions, however, and have absolutely nothing to do with the normal upgrade process
coneybeare
Thanks Kristopher - and yes I agree. My problem was I had used the NSUserDefaults to store programmatic events and had relied on them being reset when the app is installed. All my testing on the iPhone device (and Apples testing) tested the app as a new install. Without any documentation or way to test as an update I was unable to repeat the update crash all our customers are now experiencing. To sum up - probably a lesson learned the hard way!!
Nick Cartwright
+1  A: 

I beleive the answer is YES, it will persist. This also fully documented under the Application Directory chapter in the Apple iPhone OS Programming Guide.

leon