Quantcast
Channel: Check if my IOS application is updated - Stack Overflow
Viewing all articles
Browse latest Browse all 9

Answer by Buntylm for Check if my IOS application is updated

$
0
0

I think, given answers are good when you've a small scale application but when you working on a large-scale iOS apps with a long roadmap you definitely need a strong futuristic solution with benefits like.

  1. Better compare logic that works fine with all possibilities (2.0/2.0.0 etc).
  2. Take specific action during migration, assume when user migratingfrom version 1.0 to 2.0 verses 1.1 to 2.0.
  3. Reset the cached version when the user reset the app (Logout).

Below is the code snippet that I used in one of my iOS App.

public enum VersionConfigResponse {    case freshInstalled    case versionGreater    case versionEqualOrLesser    case currentVersionEmpty}/* Config manager responsible to handle the change needs to be done when user migrate from one Version to another Version. */public class VersionConfig {    public static let shared = VersionConfig()    private init() { }    private let versionKey = "SAVED_SHORT_VERSION_STRING"    /*     Cache the existing version for compare during next app launch.     */    private var storedVersion : String?  {        get {            return UserDefaults.standard.object(forKey: versionKey) as? String        } set {            UserDefaults.standard.set(newValue, forKey: versionKey)            UserDefaults.standard.synchronize()        }    }    /*     Validate the current version with saved version, if greater do clean.     */    public func validate(currentVersion: String?) -> VersionConfigResponse  {        guard let currentVersion = currentVersion else {            return .currentVersionEmpty        }        guard let sVersion = storedVersion else {            self.storedVersion = currentVersion            self.freshInstalled()            return .freshInstalled        }        if currentVersion.compare(sVersion, options: .numeric, range: nil, locale: nil) == .orderedDescending    {            self.storedVersion = currentVersion            self.userMigrated(fromVersion: sVersion, toVersion:currentVersion)            return .versionGreater        } else {            return .versionEqualOrLesser        }    }    private func userMigrated(fromVersion: String, toVersion: String)   {        //take your action here...    }    private func freshInstalled()   {        //take your action here...    }    /*     Remove saved version if user reset(logout) the app.     */    public func reset() {        self.storedVersion = nil    }}//trigger version config with current versionVersionConfig.shared.validate(currentVersion: "1.0.0")//reset when user logsoutVersionConfig.shared.reset()

Viewing all articles
Browse latest Browse all 9

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>