【问题标题】:Downloading images from firebase storage swift 2.2从 Firebase 存储 swift 2.2 下载图像
【发布时间】:2016-07-15 17:01:16
【问题描述】:

我有一个项目,其中有一个图像视图(在 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 存储中的图像,并且我希望应用程序继续显示更新的图像,

谢谢!!

【问题讨论】:

  • 作为测试,如果您遵循Download Files 页面中列出的代码指南会发生什么?特别是在内存中下载部分。即松开 dispatch_async 调用。是不是更快了?
  • 只有你会得到图片或其他带有图片的细节
  • @Jay 如果没有 dispatch_async 会更慢..
  • 嗯,还有其他事情。我们有一个简单的应用程序,它填充了 10 张左右的图像,并且几乎可以立即完成。

标签: firebase swift2 firebase-storage


【解决方案1】:

Kingfisher 库可用于缓存图像。它也检查图像的变化。安装完 kingfisher lib.you 可以执行以下操作:

imageView.kf_setImageWithUrl(imageUrl)

【讨论】:

  • 我安装了 kingfisher,它说“UIImage 类型的值没有成员 kf_setImageWithUrl”,你能给我一些代码示例吗?
  • 将它与 UIImageView 一起使用,并确保您已经导入了 kingfisher。
  • 我做了,我只是为了库,我刚刚添加了“pod 'Kingfisher', '~> 2.4'”并运行了 pod install,够了吗?
  • 将导入 Kingfisher 添加到 your.swift 文件中。
  • 与图像视图一起使用。 IMAGEVIEW.kf_(输入后您会看到建议)
猜你喜欢
  • 2016-12-28
  • 2017-01-16
  • 2021-05-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-25
  • 2019-03-11
  • 2022-01-02
相关资源
最近更新 更多