Create a new NSObject class and copy the following code into this class.
hkcheckversionmanager.swift//projectmanager////Created by Ishakan on 2017/12/29.//Copyright? 2017 Liuhuakun. All rights Reserved.//import Uikitclass Hkcheckversionmanager:nsobject {////+////-Parameter A Ppid:apple ID-the developer account corresponding app gets init (appid:string) {super.init ()//Get the latest version number on AppStore let AP PUrl = Url.init (string: "http://itunes.apple.com/lookup?id=" + appId) Let appmsg = try? String.init (contentsof:appurl!, encoding:. UTF8) Let appmsgdict:nsdictionary = getdictfromstring (jstring:appmsg!) Let Appresultsarray:nsarray = (appmsgdict["Results"] as? Nsarray)! Let appresultsdict:nsdictionary = Appresultsarray.lastobject as! Nsdictionary Let appstoreversion:string = appresultsdict["Version"] as! String Let appstoreversion_float:float = Float (appstoreversion)! Gets the version number used by the current phone installation let localversion:string = bundle.main.infodictionary! ["CfbundleshortversionstriNg "] as! String Let localversion_float:float = Float (localversion)! Whether the user is set to no longer prompt let Userdefaults = userdefaults.standard let res = Userdefaults.bool (forkey: "No_alert_again") Version number on AppStore is greater than local version number-description is updated if appstoreversion_float > Localversion_float &&!res { Let ALERTC = Uialertcontroller.init (title: "Version updated", message: "Whether to go to update", Preferredstyle:. Alert) Let Yesaction = Uialertaction.init (title: "Go to update", style:. Default, Handler: {(handler) in Self.updateapp (Appid:appid) }) Let Noaction = Uialertaction.init (title: "Next Time", Style:. Cancel, Handler:nil) let CancelA ction = Uialertaction.init (title: "No longer prompted", style:. Default, Handler: {(handler) in Self.noalertagain () }) alertc.addaction (yesaction) alertc.addaction (noaction) alertc.addaction (CancelA ction) UIApplication.shared.keyWindow? RootviEwcontroller?. Present (ALERTC, Animated:true, Completion:nil)}}//Go to update func Updateapp (appid:string) { Let Updateurl:url = Url.init (string: "http://itunes.apple.com/app/id" + appId)! UIApplication.shared.open (UpdateUrl, Options: [:], Completionhandler:nil)}//no longer prompted for Func Noalertagain () { Let Userdefaults = Userdefaults.standard Userdefaults.set (true, Forkey: "No_alert_again") userdefaults.s Ynchronize ()}//jsonstring to dictionary func getdictfromstring (jstring:string), nsdictionary {let Jsondat A:data = Jstring.data (using:. UTF8)! Let dict = try? Jsonserialization.jsonobject (With:jsondata, Options:. mutablecontainers) If dict! = Nil {return dict a s! Nsdictionary} return Nsdictionary ()}}
Call a code in the class that you want to detect
Version detection _ = Hkcheckversionmanager.init (appId: "Your Apple ID")
iOS development One sentence Code detection app version of update-swift version