在此代码中,我们使用“alamofire”下载图像,但在那里我想要替换图像,所以请帮助我。当我得到响应然后图像存在然后我得到错误代码516(已经存在图像)所以请在得到回复后帮助我。 我想要替换旧图像或删除旧图像。
func setUI() {
self.btnCancel.layer.borderWidth = 1.0
self.btnCancel.layer.cornerRadius = 3.0
self.btnCancel.addShadowView()
print("-------------------------------- method Call")
if let url = NSURL(string: strFileName) {
print(url)
let destination = Alamofire.Request.suggestedDownloadDestination(directory: .DocumentDirectory, domain: .UserDomainMask)
self.request = Alamofire.download(.GET, url, parameters: nil, encoding: ParameterEncoding.URL,destination:destination)
.progress { bytesRead, totalBytesRead, totalBytesExpectedToRead in
dispatch_async(dispatch_get_main_queue()) {
print("Total bytes read on main queue: \(totalBytesRead)")
print("Progress on main queue: \(Float(totalBytesRead) / Float(totalBytesExpectedToRead))")
print("totalBytesExpectedToRead",totalBytesExpectedToRead)
self.CountPercentage.text! = String(format: "%.f%%",self.viewProgressBar.progress * 100)
self.viewProgressBar.progress = (Float(totalBytesRead) / Float(totalBytesExpectedToRead))
}
}
.response { request, response, _, error in
print("\(request?.URL)") // original URL request
print(error)
if !(error == nil) {
if !(error!.code != NSURLErrorCancelled) {
print("cancel----------")
} else if (error!.code == 516) {
print("fileURL: \(destination(NSURL(string: "")!, response!))")
let filePath = destination(NSURL(string: "")!, response!)
self.alertAction("File downloaded successfully.", filePath: filePath)
} else {
CommonMethods.sharedInstance.showAlertWithMessage((error?.localizedDescription)!, withController: self)
}
} else {
print("fileURL: \(destination(NSURL(string: "")!, response!))")
let filePath = destination(NSURL(string: "")!, response!)
self.alertAction("File downloaded successfully.", filePath: filePath)
}
}
}
}