简体   繁体   中英

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.

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:

不工作的形象

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

Hope it helps!

There's an open source library available called Harpy that will accomplish this for you! It provides the ability to check for updates on startup, daily, or weekly, and it uses iTunes to do the checking, so config is really minimal.

Configuration Steps are :

  1. Install via Github or via Cocoapods
  2. In Appdelegate.m didFinishLaunchingWithOptions method add the below code :

     - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // Present Window before calling Harpy [self.window makeKeyAndVisible]; // Set the UIViewController that will present an instance of UIAlertController [[Harpy sharedInstance] setPresentingViewController:_window.rootViewController]; // Optional Set the Delegate to track what a user clicked on, or to use a custom UI to present your message. [[Harpy sharedInstance] setDelegate:self]; // Optional [[Harpy sharedInstance] setAlertControllerTintColor:@"<#alert_controller_tint_color#>"]; //Optional [[Harpy sharedInstance] setAppName:@"<#app_name#>"]; /* Optional Set the Alert Type for your app By default, Harpy is configured to use HarpyAlertTypeOption */ [[Harpy sharedInstance] setAlertType:<#alert_type#>]; /* Optional If your application is not available in the US App Store, you must specify the two-letter country code for the region in which your applicaiton is available. */ [[Harpy sharedInstance] setCountryCode:@"<#country_code#>"]; /* Optional Overrides system language to predefined language. Please use the HarpyLanguage constants defined in Harpy.h. */ [[Harpy sharedInstance] setForceLanguageLocalization:<#HarpyLanguageConstant#>]; // Perform check for new version of your app [[Harpy sharedInstance] checkVersion]; } 

Its DONE !

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM