Search code examples
iosswiftcompatibility

How to discontinue old versions of apps?


I'm making an app and am planning for the future. If for example the first version of my app didn't work with my back end in the future. Is there a way or best practise to stop the app and basically say this version is no longer compatible to continue using you will have to upgrade.

My app uses firebase as a backend. The way around it I have thought of is on every load getting a bool from firebase that says if this version of the app is still compatible. If false I would then put a notification over a blank screen saying you have to upgrade from the appstore. I'm wondering if there is a better normal way to do this/if people just don't do this.

I know this is absolutely not what I'd like to do but I'm just looking into the option.


Solution

  • You can add an attribute to your Firebase database called version and there you should add the minimum version number from which your app would work properly, and then check the version of your app, directly from AppDelegate. It has the benefit of working with Firebase directly, no other framework is needed.

    Your Firebase tree should look like that:

     YourApp-
        - version: 1.5
        - otherDataFromYourApp
    

    And then you can retrieve the version number from the database, like this, in AppDelegate, and compare it to the minimum version:

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        FIRApp.configure()
        // get the current version of your app
        let versionObject: AnyObject? = Bundle.main.infoDictionary!["CFBundleShortVersionString"] as AnyObject?
        let version = Float(versionObject as! String)!
        // get the minimum version from Firebase
        var minimumVersion = Float()
        let ref = FIRDatabase.database().reference()
        ref.child("version").observe(FIRDataEventType.value, with: { snap in
            print(snap.value!)
            minimumVersion = snap.value! as! Float
            // compare the versions
            if minimumVersion > version{
                print("this is not a valid version")
                self.window?.rootViewController = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "MustUpdateViewController")
            }
        })
        return true
    }
    

    Then, all you have to do is to create a new ViewController with the Storyboard ID of MustUpdateViewController, design it as per your requirements, and each time your minimum app version changes, you need to change the value of version from Firebase. Example in Storyboard:

    not working image

    That's all you have to do, in just a few lines of code and some design in Storyboard...

    Hope it helps!