//去appStore檢查更新
private func checkUpdate() {
let path = NSString(format: "http://itunes.apple.com/cn/lookup?id=%@", "自己的AppID") as String
let url = NSURL(string: path)
let request = NSMutableURLRequest(url: url! as URL, cachePolicy: NSURLRequest.CachePolicy.reloadIgnoringLocalAndRemoteCacheData, timeoutInterval: 10)
request.httpMethod = "POST"
NSURLConnection.sendAsynchronousRequest(request as URLRequest, queue: OperationQueue()) { (response, data, error) in
let receiveStatusDic = NSMutableDictionary()
if data != nil {
do {
let dic = try JSONSerialization.jsonObject(with: data!, options: JSONSerialization.ReadingOptions.mutableContainers) as! [String: Any]
print(dic)
if let resultCount = dic["resultCount"] as? NSNumber {
if resultCount.intValue > 0 {
receiveStatusDic.setValue("1", forKey: "status")
if let arr = dic["results"] as? NSArray {
if let dict = arr.firstObject as? NSDictionary {
if let version = dict["version"] as? String {
receiveStatusDic.setValue(version, forKey: "version")
UserDefaults.standard.set(version, forKey: "Version")
UserDefaults.standard.synchronize()
}
}
}
}
}
}catch let error {
receiveStatusDic.setValue("0", forKey: "status")
}
}else {
receiveStatusDic.setValue("0", forKey: "status")
}
self.performSelector(onMainThread: #selector(self.checkUpdateWithData(data:)), with: receiveStatusDic, waitUntilDone: false)
}
}
@objc private func checkUpdateWithData(data: NSDictionary) {
let status = data["status"] as? String
let localVersion = Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString") as! String
if status == "1" {
let storeVersion = data["version"] as! String
self.compareVersion(localVersion: localVersion, storeVersion: storeVersion)
return
}
if let storeVersion = UserDefaults.standard.object(forKey: "Version") as? String {
self.compareVersion(localVersion: localVersion, storeVersion: storeVersion)
}
}
private func compareVersion(localVersion: String, storeVersion: String) {
if localVersion.compare(storeVersion) == ComparisonResult.orderedAscending {
print("去更新")
//let alertView = UIAlertView.init(title: "提示", message: "版本有更新,請前往AppStore下載", delegate: self, cancelButtonTitle: "取消", otherButtonTitles: "前往下載")
//alertView.tag = 1
//alertView.show()
} else {
print("是最新版本")
//SVPManager.svpShowMessage(message: "已經(jīng)是最新版本了", timeInterval: nil)
}
}
swift3 去appStore檢查更新
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
- 文/潘曉璐 我一進(jìn)店門乍恐,熙熙樓的掌柜王于貴愁眉苦臉地迎上來评疗,“玉大人,你說我怎么就攤上這事茵烈“俅遥” “怎么了?”我有些...
- 文/不壞的土叔 我叫張陵呜投,是天一觀的道長加匈。 經(jīng)常有香客問我,道長仑荐,這世上最難降的妖魔是什么雕拼? 我笑而不...
- 正文 為了忘掉前任,我火速辦了婚禮粘招,結(jié)果婚禮上啥寇,老公的妹妹穿的比我還像新娘。我一直安慰自己男图,他們只是感情好示姿,可當(dāng)我...
- 文/花漫 我一把揭開白布甜橱。 她就那樣靜靜地躺著逊笆,像睡著了一般。 火紅的嫁衣襯著肌膚如雪岂傲。 梳的紋絲不亂的頭發(fā)上难裆,一...
- 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼谍憔!你這毒婦竟也來了匪蝙?” 一聲冷哼從身側(cè)響起,我...
- 正文 年R本政府宣布溢谤,位于F島的核電站,受9級特大地震影響憨攒,放射性物質(zhì)發(fā)生泄漏世杀。R本人自食惡果不足惜,卻給世界環(huán)境...
- 文/蒙蒙 一肝集、第九天 我趴在偏房一處隱蔽的房頂上張望瞻坝。 院中可真熱鬧,春花似錦杏瞻、人聲如沸所刀。這莊子的主人今日做“春日...
- 文/蒼蘭香墨 我抬頭看了看天上的太陽浮创。三九已至,卻和暖如春砌函,著一層夾襖步出監(jiān)牢的瞬間斩披,已是汗流浹背溜族。 一陣腳步聲響...
推薦閱讀更多精彩內(nèi)容
- 1、現(xiàn)在的應(yīng)用升級問題闸婴,蘋果已經(jīng)幫我們解決了坏挠,就是在我們應(yīng)用中不需要提示升級問題,手機(jī)系統(tǒng)會自動給升級到最新版本(...
- iOS軟件檢查更新,每次啟動檢測Appstore是否有更新,每一次更新只提醒一次 Version 1.0.2 1....
- 1、現(xiàn)在的應(yīng)用升級問題庇楞,蘋果已經(jīng)幫我們解決了榜配,就是在我們應(yīng)用中不需要提示升級問題,手機(jī)系統(tǒng)會自動給升級到最新版本(...
- 怎樣反思自己的教學(xué)——學(xué)習(xí)杜威《我們怎樣思維》有感 2015-01-13 14:56:52 來源:普寧市第三中學(xué)網(wǎng)...