0
func downloadProgress(bytesRead: Int64, totalBytesRead: Int64,
totalBytesExpectedToRead: Int64) {
let percent = Float(totalBytesRead)/Float(totalBytesExpectedToRead)
dispatch_async(dispatch_get_main_queue(), {
self.progress.setProgress(percent,animated:true)
})
print("Progress:\(percent*100)%")
}
func downloadResponse(request: NSURLRequest?, response: NSHTTPURLResponse?,
data: NSData?, error:NSError?) {
if let error = error {
if error.code == NSURLErrorCancelled {
self.cancelledData = data
} else {
print("Failed to download file: \(response) \(error)")
}
} else {
print("Successfully downloaded file: \(response)")
}
}
@IBAction func continueBtnClick(sender: AnyObject) {
if let cancelledData = self.cancelledData {
self.downloadRequest = Alamofire.download(resumeData: cancelledData,
destination: destination)
self.downloadRequest.progress(downloadProgress)
self.downloadRequest.response(completionHandler: downloadResponse)
self.stopBtn.enabled = true
self.continueBtn.enabled = false
}
}
這些代碼在Alamofire 3.1上運行良好,但在升級到Swift 3.0和Alamofire 4.0後拒絕工作。Alamofire方法無法升級到4.0後工作
下面的兩個行顯示錯誤 「沒有這樣的memeber FO進展」 和
- self.downloadRequest.progress(downloadProgress)
- self.downloadRequest.response(completionHandler 「響應沒有這樣的成員」: downloadResponse)
我該如何解決這兩個問題?
謝謝。
謝謝你的建議。有用。 – jdleung
@jdleung太棒了!我很高興能夠幫忙 – tech4242