使用AlamofireImage进行图像下载?

有没有办法使用AlamofireImage下载图像并获得有关下载进度的某种反馈,同时利用它的UIImage扩展,图像filter和图像缓存的强大function?

我知道我可以回到简单的Alamofire.request + responseImage但我想保持简单并使用UIImageView扩展

谢谢!

目前没有任何方法可以在下载图像时使用AlamofireImage和UIImageView扩展来接收进度更新。 它最初没有添加的原因是,似乎大多数用户不需要这样的function。 我想讨论更多,看看这是否是我们在未来版本中实际想要添加到AlamofireImage的function。

您是否愿意通过您的用例打开一个问题? 我只想知道您期望它如何工作以及您实际需要进度报告的原因。

使用Swift 3.0.2试试这个:

 let utilityQueue = DispatchQueue.global(qos: .utility) let url = "http://sofzh.miximages.com/ios/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) } } 

使用Alamofire下载图像与进程

下载具有进度的文件

 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") } }