带有 FireBase 的 SDWebImage [英] SDWebImage with FireBase

查看:21
本文介绍了带有 FireBase 的 SDWebImage的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了以下函数来从 firebase 存储中获取图像:

I created the below function to fetch image from firebase storage:

func downloadImageFromFirebase(_ imageNameOnFireBase: String, imageViewToBeFilled: UIImageView) {
    let storage = Storage.storage()
    let reference: StorageReference = storage.reference().child(imageNameOnFireBase)
    reference.downloadURL { url , error in
        if error != nil {
            print(error!.localizedDescription)
            imageViewToBeFilled.image = UIImage(named: "default")
        } else {
            if let url = url {
                do {
                    let data = try Data.init(contentsOf: url)
                    imageViewToBeFilled.image = UIImage(data: data)
                } catch {
                    print("Error fetching URL")
                    imageViewToBeFilled.image = UIImage(named: "default")
                }
            }
        }
    }
} 

多次使用该功能会导致加载延迟,如何更快更可靠地下载图片?

When using the function many times it causes loading delay , How can i approach faster and more reliable way of downloading the images ?

推荐答案

您应该能够使用 URL 从 Firebase 获取图像,并且使用 SDWebImage 它将使您的应用程序具有非常快的加载和滚动时间,因为图像只是加载一次.可在此处找到有关此方面的出色教程:https://www.youtube.com/watch?v=XPAaxF0rQy0

You should be able to fetch images from Firebase with URLs, and using SDWebImage it will enable your app to have very fast loading and scrolling times as the images are only loaded once. An excellent tutorial for this can be found here: https://www.youtube.com/watch?v=XPAaxF0rQy0

(他用 Firebase Storage 教授它)

(He teaches it with Firebase Storage)

这篇关于带有 FireBase 的 SDWebImage的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆