Image downloading with progress using AlamofireImage?

孤街醉人 提交于 2019-12-10 15:55:36

问题


Is there any way to download an image using AlamofireImage and get some kind of feedback about the download progress while leveraging the power of it's UIImage Extensions, Image Filters and Image Cache?

I know I can fallback to a plain Alamofire.request + responseImage but I'd like to keep things simple and make use of the UIImageView Extension.

Thank you!


回答1:


There is not any way at the moment to use AlamofireImage alongside the UIImageView extension to receive progress updates when downloading an image. The reason it wasn't added initially was that it didn't seem like the majority of users would need such a feature. I would love to discuss more to see if this is a feature that we'd actually like to add to AlamofireImage in a future release.

Would you be willing to open up an issue walking through your use case? I would just like to know exactly how you would expect it to work and why you actually need the progress reporting.




回答2:


Try this with 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)
            }
    }



回答3:


Use Alamofire download image with process

Downloading a File 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")
             }
         } 


来源:https://stackoverflow.com/questions/33477065/image-downloading-with-progress-using-alamofireimage

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!