使用 AlamofireImage 进行图像下载?

Image downloading with progress using AlamofireImage?

有没有什么方法可以使用 AlamofireImage 下载图像并获得有关下载进度的某种反馈,同时利用其 UIImage 扩展、图像过滤器和图像缓存 的强大功能?

我知道我可以回退到普通的 Alamofire.request + responseImage 但我想保持简单并利用 UIImageView Extension .

谢谢!

在进程中使用 Alamofire 下载图像

正在下载文件w/Progress

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

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

您愿意提出一个问题来遍历您的用例吗?我只是想确切地知道您希望它如何工作以及为什么您实际上需要进度报告。

尝试使用 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)
            }
    }