有什么方法可以使用AlamofireImage下载图像并获得关于下载进度的反馈,同时利用它的UIImage扩展、图像过滤器和图像缓存的功能
我知道我可以回到普通的Alamofire.request + responseImage,但我希望保持简单,并使用UIImageView扩展。
谢谢!
发布于 2015-11-03 15:40:40
在下载图像时,没有任何方法可以使用AlamofireImage和UIImageView扩展来接收进度更新。它最初没有被添加的原因是它看起来不像是大多数用户都需要这样的功能。我想进一步讨论一下,看看这是否是我们希望在将来的版本中添加到AlamofireImage中的一个特性。
您愿意在用例中打开一个问题吗?我只想确切地知道你期望它如何工作,以及你为什么真正需要进度报告。
发布于 2017-03-24 09:32:10
用Swift 3.0.2试试这个:
let utilityQueue = DispatchQueue.global(qos: .utility)
let url = "http://kingofwallpapers.com/code/code-006.jpg"
Alamofire.download(url)
.downloadProgress(queue: utilityQueue) { progress in
print("Download Progress: \(progress.fractionCompleted)")
}
.responseData { response in
print("Response is \(response)")
if let data = response.result.value {
let image = UIImage(data: data)
}
}发布于 2015-11-02 14:18:56
使用Alamofire下载图像和进程
下载文件w/进度
Alamofire.download(.GET, "url...", destination: destination)
.progress { bytesRead, totalBytesRead, totalBytesExpectedToRead in
print(totalBytesRead)
// This closure is NOT called on the main queue for performance
// reasons. To update your ui, dispatch to the main queue.
dispatch_async(dispatch_get_main_queue()) {
print("Total bytes read on main queue: \(totalBytesRead)")
}
}
.response { _, _, _, error in
if let error = error {
print("Failed with error: \(error)")
} else {
print("Downloaded file successfully")
}
} https://stackoverflow.com/questions/33477065
复制相似问题