//去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: "已经是最新版本了", timeInterval: nil)
}
}
swift3 去appStore检查更新
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- 1、现在的应用升级问题,苹果已经帮我们解决了,就是在我们应用中不需要提示升级问题,手机系统会自动给升级到最新版本(...
- iOS软件检查更新,每次启动检测Appstore是否有更新,每一次更新只提醒一次 Version 1.0.2 1....
- 1、现在的应用升级问题,苹果已经帮我们解决了,就是在我们应用中不需要提示升级问题,手机系统会自动给升级到最新版本(...
- 怎样反思自己的教学——学习杜威《我们怎样思维》有感 2015-01-13 14:56:52 来源:普宁市第三中学网...