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