从 Firebase 存储 swift 2.2 下载图片



我有一个项目,我有一个图像视图(在Xcode 7.3中)。我需要显示来自我的 firebase 存储和我的 UIImageView 的图像,现在我正在使用以下代码:(但它真的很慢 - 每次我进入视图需要 3-4 秒才能显示我的图像)

func showImage(){
    FIRStorage.storage().referenceForURL("https://firebasestorage.googleapis.com/v0/b/restaurantproject-27368.appspot.com/o/bestdeal.jpg?alt=media&token=dcbd9da1-d368-48ef-8ed2-a861103e4ab8").dataWithMaxSize(10 * 1024 * 1024, completion: { (data, error) in
        dispatch_async(dispatch_get_main_queue()) {
            self.myImageView.image = UIImage(data: data!)
        }        
    })
}

有没有更好的方法?(另外,我需要以某种方式将其缓存在我的设备中,但我每次进入应用程序时都需要它来检查我的图像,因为我有时需要更改Firebase存储中的图像,并且我希望应用程序继续显示更新的图像,

谢谢!!

翠鸟库可用于缓存图像。它还检查图像中的更改。安装 kingfisher lib.您可以执行以下操作:

imageView.kf_setImageWithUrl(图片网址)

最新更新