Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

force reset NSUserDefault on iPhone App upgrade

i want to force reset to NSUserDefault whenever user update my app. why i need this because every update include some new information abt user. as some info (token) already present in NSUserDefault my app does not call to my web service. due to that fact i dont have new user info. and also i dont want to write if..else statement for every new release.

thanks so much. hope my question is pretty clear.

like image 595
Nnp Avatar asked Feb 27 '23 08:02

Nnp


2 Answers

Check this out:

[NSUserDefaults resetStandardUserDefaults]

For more info check the NSUserDefaults Class reference.

What you can do is save on the defaults the current version of your app. All the time that the user open the app you check the saved version against the current version. In the case of an update the current version will be different from the saved version, and so you know that it's time to clean the user defaults. After cleaned, you save the new value for the current version.

like image 185
vfn Avatar answered Mar 08 '23 16:03

vfn


You can save your current application version into NSUserDefaults when you start up your application. Before doing so, you can just do a check to see if the actual application version is greater than the version stored in NSUserDefaults. If it is, you know that the user has just upgraded, and you can remove and information (such as the token) from the defaults using removeObjectForKey

like image 40
Reed Olsen Avatar answered Mar 08 '23 16:03

Reed Olsen