NetworkTool.checkUpdate { releaseNotes,isNeedUpdate in
print(releaseNotes,isNeedUpdate)
if isNeedUpdate {
if !kWindow.subviews.contains(self.updateView) {
kWindow.addSubview(self.updateView)
}
if releaseNotes.count != 0 {
self.updateView.releaseNotesLabel.text = releaseNotes
}
self.updateView.snp.makeConstraints { (make) in
make.left.right.top.bottom.equalToSuperview().offset(0)
}
}
else {
}
}
工具类中的代码 NetworkTool
static func checkUpdate(_ handler:((_ releaseNotes:String,_ isNeedUpdate:Bool)->())?) {
let localVersion = Bundle.main.infoDictionary!["CFBundleShortVersionString"] as! String
NetworkTool.checkVersion { (appStoreVersion,releaseNotes) in
var boolValue = false
print("localVersion=",localVersion,"appStoreVersion=",appStoreVersion)
if appStoreVersion == "0.0" {
boolValue = false
}
let result = localVersion.compare(appStoreVersion)
if result == .orderedAscending {
boolValue = true
}
else {
boolValue = false
}
handler?(releaseNotes,boolValue)
}
}
static func checkVersion(success:@escaping((String,String)->())) {
let appstore_url = URL(string:appStoreVersionUrl)
if let url = appstore_url {
AF.request(url).responseJSON { (response) in
if let value = response.value {
let dic = value as! Dictionary<String, Any>
print(dic)
let results = dic["results"] as! [[String:Any]]
if results.count >= 1 {
let dict = results.first!
let version = "\(dict["version"] ?? 0.0)"
let releaseNotes = "\(dict["releaseNotes"] ?? "")"
success(version,releaseNotes)
}
}
}
}
}
|