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

Answer by Cœur for Check if my IOS application is updated

$
0
0

version with an important improvement over the accepted answer:

  • using infoDictionary instead of objectForInfoDictionaryKey guaranties that the result is independent from device language, otherwise you may end up in some rare cases believing that there is an upgrade when in reality it is just a device language change
  • using a UserDefaults key identical to the main Bundle infoDictionary for clarity on what is exactly stored
  • factoring setting currentVersion code
  • Swift 3 syntax

Code:

    let standardUserDefaults = UserDefaults.standard    let shortVersionKey = "CFBundleShortVersionString"    let currentVersion = Bundle.main.infoDictionary![shortVersionKey] as! String    let previousVersion = standardUserDefaults.object(forKey: shortVersionKey) as? String    if previousVersion == currentVersion {        // same version    } else {        // replace with `if let previousVersion = previousVersion {` if you need the exact value        if previousVersion != nil {            // new version        } else {            // first launch        }        standardUserDefaults.set(currentVersion, forKey: shortVersionKey)        standardUserDefaults.synchronize()    }

Viewing all articles
Browse latest Browse all 9

Trending Articles



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