ioslifecycleapp-update

iOS app, is there a way to subscribe to an event when an app is updated through AppStore?


I need to cleanup some properties stored in NSUserDefaults for iOS app when it is updated to new version.

Is there a way to be notified when such an app update is going to happen or has happened?

Also is my assumption correct that when application is updated, NSUserDefaults are not automatically cleaned?


Solution

  • The UserDefaults are not modified on an app-update. What you are essentially asking is how to implement versioning for your data. The most basic way to do this is by using a version value in your app and add it to your UserDefaults.

    Sample flow on app start:

    1. You have defined a version of "1.0" in your code and a "Version" key
    2. On app start, UserDefaults is accessed and your "Version" key is checked to see if a value exists for it.
    3. If a value exists and it is equal to the version defined above, that means the app has already been launched with this version previously so no work needs to be done.
    4. If a value exists but it is not equal (this will happen for future versions) to the version defined above or no value exists at all, you can perform your cleanup since this is the first time you have launched this version.
    5. Lastly, update the value in UserDefaults to the current version.