4

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!

Sendoa
  • 4,705
  • 5
  • 27
  • 21

3 Answers3

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.

cnoon
  • 16,575
  • 7
  • 58
  • 66
  • Thanks a lot for your answer @cnoon! I've just posted an issue https://github.com/Alamofire/AlamofireImage/issues/48 ;-) – Sendoa Nov 03 '15 at 21:12
1

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)
            }
    }
Sour LeangChhean
  • 7,089
  • 6
  • 37
  • 39
0

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")
             }
         } 
Lokesh Dudhat
  • 449
  • 3
  • 10
  • As I said in my original post, *«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»*. This is in order to take advantage of caching and other helpful functionalities. – Sendoa Nov 02 '15 at 17:41