force reset NSUserDefault on iPhone App upgrade
i want to force r开发者_开发技巧eset 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.
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.
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
精彩评论