从Firebase缓存图片 [英] Cache Image from Firebase
问题描述
我有多个单元格,当前拥有Firebase中的不同照片。每当用户加载这些图像,然后滚动,它们被重新下载,快速吃掉数据。我发现这与任何有计量数据计划的用户有关。我能做些什么来解决这个问题? Firebase是否提供任何选项来缓存下载的图片?
这是我目前将图片调入单元格的方式:
if let imageName = post [image] as?字符串{
let imageRef = FIRStorage.storage()。reference()。child(images / \(imageName))
imageRef.data(withMaxSize:25 * 1024 * 1024,completion:{ (data,error) - >如果错误== nil {
let image = UIImage(data:data!)
cell.postImageView.image = image
$ c $使用
$ n $ n
$ $ p $ let url = URL(string:url_of_your_image)
imageView.kf.setImage(with:url)
I have multiple cells that currently hold different photos from Firebase. Every time a user loads these images then scrolls, they are re-downloaded which eats up data fast. I find this concerning to any user who has a metered data plan. What could I do to solve this? Does Firebase offer any options to cache downloaded images?
This is how I am currently calling an image into a cell:
if let imageName = post["image"] as? String {
let imageRef = FIRStorage.storage().reference().child("images/\(imageName)")
imageRef.data(withMaxSize: 25 * 1024 * 1024, completion: { (data, error) -> Void in if error == nil {
let image = UIImage(data: data!)
cell.postImageView.image = image
Use Kingfisher to cache images. It's light and very easy to use. Just pass your url from firebase and it will automatically cache it.
let url = URL(string: "url_of_your_image")
imageView.kf.setImage(with: url)
这篇关于从Firebase缓存图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!