private func checkUpdate() { let path = NSString(format: "http://itunes.apple.com/cn/lookup?id=%@",AppConfig.appStoreID) as String let url = NSURL(string: path) let request = NSMutableURLRequest(URL: url!,cachePolicy: NSURLRequestCachePolicy.ReloadIgnoringLocalAndRemoteCacheData,timeoutInterval: 10.0) request.HTTPMethod = "POST" NSURLConnection.sendAsynchronousRequest(request,queue: NSOperationQueue()) { (response,data,error) in let receiveStatusDic = NSMutableDictionary() if data != nil { do { let dic = try NSJSONSerialization.JSONObjectWithData(data!,options: NSJSONReadingOptions.MutableContainers) if let resultCount = dic["resultCount"] as? NSNumber { if resultCount.integerValue > 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") NSUserDefaults.standardUserDefaults().setObject(version,forKey: "Version") NSUserDefaults.standardUserDefaults().synchronize() } } } } } }catch let error { log.debug("checkUpdate -------- \(error)") receiveStatusDic.setValue("0",forKey: "status") } }else { receiveStatusDic.setValue("0",forKey: "status") } self.performSelectorOnMainThread(#selector(AppDelegateSplash.checkUpdateWithData(_:)),withObject: receiveStatusDic,waitUntilDone: false) } } @objc private func checkUpdateWithData(data: NSDictionary) { let status = data["status"] as? String let localVersion = NSBundle.mainBundle().objectForInfoDictionaryKey("CFBundleShortVersionString") as! String if status == "1" { let storeVersion = data["version"] as! String self.compareVersion(localVersion,storeVersion: storeVersion) return } if let storeVersion = NSUserDefaults.standardUserDefaults().objectForKey("Version") as? String { self.compareVersion(localVersion,storeVersion: storeVersion) } } private func compareVersion(localVersion: String,storeVersion: String) { if localVersion.compare(storeVersion) == NSComparisonResult.OrderedAscending { //做你想做的事情 } }