1.下載文件顯示進(jìn)度
A.任何DownloadRequest都可以使用downloadProgress API得到下載進(jìn)度麦撵。
Alamofire.download("https://httpbin.org/image/png")
.downloadProgress { progress in
print("Download Progress: \(progress.fractionCompleted)")
}
.responseData { response in
if let data = response.result.value {
let image = UIImage(data: data)
}
}
B.queue參數(shù)定義了下載進(jìn)度閉包在哪個(gè)DispatchQueue調(diào)用泌枪。
let utilityQueue = DispatchQueue.global(qos: .utility)
Alamofire.download("https://httpbin.org/image/png")
.downloadProgress(queue: utilityQueue) { progress in
print("Download Progress: \(progress.fractionCompleted)")
}
.responseData { response in
if let data = response.result.value {
let image = UIImage(data: data)
}
}