首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用AlamofireImage进行图像下载?

使用AlamofireImage进行图像下载?
EN

Stack Overflow用户
提问于 2015-11-02 11:57:08
回答 3查看 3.1K关注 0票数 4

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

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

谢谢!

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2015-11-03 15:40:40

在下载图像时,没有任何方法可以使用AlamofireImage和UIImageView扩展来接收进度更新。它最初没有被添加的原因是它看起来不像是大多数用户都需要这样的功能。我想进一步讨论一下,看看这是否是我们希望在将来的版本中添加到AlamofireImage中的一个特性。

您愿意在用例中打开一个问题吗?我只想确切地知道你期望它如何工作,以及你为什么真正需要进度报告。

票数 1
EN

Stack Overflow用户

发布于 2017-03-24 09:32:10

用Swift 3.0.2试试这个:

代码语言:javascript
复制
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)
            }
    }
票数 1
EN

Stack Overflow用户

发布于 2015-11-02 14:18:56

使用Alamofire下载图像和进程

下载文件w/进度

代码语言:javascript
复制
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")
             }
         } 
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33477065

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档