2016-07-15 141 views
0

我有一个项目,我有一个图像视图(在Xcode 7.3)。 我需要显示从我的firebase存储和我的UIImageView图像,现在我使用此代码: (但它非常慢 - 每次我进入视图需要3-4秒才能显示我的图像)从firebase存储swift下载图像2.2

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存储有时更改图像,我希望应用程序不断显示更新的图像,

谢谢!!

+0

作为一个测试,如果你fo请遵循[下载文件](https://firebase.google.com/docs/storage/ios/download-files)页面中列出的代码指南?具体来说就是内存下载部分。即松散dispatch_async调用。它更快吗? – Jay

+0

只有你会得到图像或其他细节 –

+0

@Jay它没有dispatch_async更慢.. – Coder123

回答

2

翠鸟库可用于缓存图像它检查图像中的变化也安装翠鸟后lib.you可以做到以下几点:。

imageView.kf_setImageWithUrl (imageUrl)

+0

我安装了翠鸟,不管它说“UIImage类型的值没有成员kf_setImageWithUrl”,你能给我一些代码示例吗? – Coder123

+0

使用它与UIImageView并确保您已导入翠鸟。 –

+0

我做过了,我只是为图书馆添加了“pod'Kingfisher','〜> 2.4'”并运行了pod install,是不是很明显? – Coder123