关于ios:使用AlamofireImage进行图像下载有进度吗?

Image downloading with progress using AlamofireImage?

是否可以使用AlamofireImage下载图像并获得有关下载进度的某种反馈,同时利用其UIImage扩展,图像过滤器和图像缓存的功能?

我知道我可以回退到普通的Alamofire.request responseImage,但是我想保持简单,并使用UIImageView扩展。

谢谢!


尝试使用Swift 3.0.2:

1
2
3
4
5
6
7
8
9
10
11
12
13
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)
            }
    }

目前无法在UIImageView扩展名旁边使用AlamofireImage来接收下载图像时的进度更新。最初未添加该功能的原因是,似乎大多数用户似乎都不需要此功能。我很想讨论更多内容,以了解这是否是我们将来要在AlamofireImage中添加的功能。

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


在进程中使用Alamofire下载映像

通过进度下载文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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")
             }
         }