使用AlamofireImage进行图像下载?
有没有办法使用AlamofireImage下载图像并获得有关下载进度的某种反馈,同时利用它的UIImage扩展,图像filter和图像缓存的强大function?
我知道我可以回到简单的Alamofire.request
+ responseImage
但我想保持简单并使用UIImageView扩展 。
谢谢!
目前没有任何方法可以在下载图像时使用AlamofireImage和UIImageView
扩展来接收进度更新。 它最初没有添加的原因是,似乎大多数用户不需要这样的function。 我想讨论更多,看看这是否是我们在未来版本中实际想要添加到AlamofireImage的function。
您是否愿意通过您的用例打开一个问题? 我只想知道您期望它如何工作以及您实际需要进度报告的原因。
使用Swift 3.0.2试试这个:
let utilityQueue = DispatchQueue.global(qos: .utility) let url = "http://sofzh.miximages.com/ios/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) } }
使用Alamofire下载图像与进程
下载具有进度的文件
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") } }
- SCNNode上的CIFilter只能在模拟器中使用
- 为什么连接回iOS背景NSURLSession等待锁定需要太长时间,导致应用程序崩溃?
- iOS应用程序提交,图片尺寸无效
- 在Parse中从用户类中检索布尔值
- 我可以用addOperationWithBlock取消添加到NSOperationQueue的Block吗?
- 视网膜显示VS正常显示色差
- 有没有办法在MonoTouch中创建本机cocoa类库?
- 更新Object时防止Realm覆盖属性
- iOS UITableViewCell,UICollectionViewCell,UITableViewHeaderFooterView和UICollectionReusableView出队和注册-使用Swift协议和泛型