SDWebImage with FireBase

喜你入骨 提交于 2020-06-13 09:32:33

问题


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 ?


回答1:


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

(He teaches it with Firebase Storage)



来源:https://stackoverflow.com/questions/61857042/sdwebimage-with-firebase

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!