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

Answer by SPatel for Check if my IOS application is updated

$
0
0

Just initialise AppVersionUpdateNotifier in app launch and conform AppUpdateNotifier protocol, enjoy.

Use: Swift 3.x

extension AppDelegate: AppUpdateNotifier {    func onVersionUpdate(newVersion: Int, oldVersion: Int) {        // do something    }    func onFirstLaunch() {        //do something    }}
    class AppVersionUpdateNotifier {        static let KEY_APP_VERSION = "key_app_version"        static let shared = AppVersionUpdateNotifier()        private let userDefault:UserDefaults        private var delegate:AppUpdateNotifier?        private init() {            self.userDefault = UserDefaults.standard        }        func initNotifier(_ delegate:AppUpdateNotifier) {            self.delegate = delegate            checkVersionAndNotify()        }        private func checkVersionAndNotify() {            let versionOfLastRun = userDefault.object(forKey: AppVersionUpdateNotifier.KEY_APP_VERSION) as? Int            let currentVersion = Int(Bundle.main.buildVersion)!            if versionOfLastRun == nil {                // First start after installing the app                delegate?.onFirstLaunch()            } else if versionOfLastRun != currentVersion {                // App was updated since last run                delegate?.onVersionUpdate(newVersion: currentVersion, oldVersion: versionOfLastRun!)            } else {                // nothing changed            }            userDefault.set(currentVersion, forKey: AppVersionUpdateNotifier.KEY_APP_VERSION)        }    }    protocol AppUpdateNotifier {        func onFirstLaunch()        func onVersionUpdate(newVersion:Int, oldVersion:Int)    }    extension Bundle {        var shortVersion: String {            return infoDictionary!["CFBundleShortVersionString"] as! String        }        var buildVersion: String {            return infoDictionary!["CFBundleVersion"] as! String        }    }

Viewing all articles
Browse latest Browse all 9

Trending Articles



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