简体   繁体   English

iOS / Swift:如何管理Feed中从Firebase下载图像

[英]iOS/Swift: How to manage image downloading from Firebase in a feed

I'm trying to implement a feed for images using Firebase Storage, think of it like the Instagram photo feed. 我正在尝试使用Firebase Storage实现图像的供稿,就像Instagram照片供稿一样。 My Problem: 我的问题:

  • I don't know how many images there are in my Firebase reference folder 我不知道我的Firebase参考文件夹中有多少张图像
  • I want only the images to be shown that have been taken, let's say in the last week 我只想显示已拍摄的图像,比如说上周

I tried downloading the images from the reference like this: 我尝试像这样从参考下载图像:

let storageRef = storage.reference()


    for i in 0...10 {

        let imageRef = storageRef.child("images/" + String(i) + ".jpg")

        imageRef.dataWithMaxSize((10 * 1024 *  1024), completion: { (data, error) -> Void in
            if (error != nil) {
                print(error)
            } else {
                let image: UIImage! = UIImage(data: data!)
                self.downloadedPhotos.append(image) //downloadedPhotos is an array of UIImages

                self.configureFeed() //takes care of some UI

            }
        })
    }

Here I run into the obvious problem: I've only downloaded 10 images, called "1","2",..., "10" 在这里,我遇到了一个明显的问题:我只下载了10张图片,分别是“ 1”,“ 2”,...,“ 10”

  • What kind of way to name the images when users upload them would you suggest? 您建议用户使用哪种方式命名图像?
  • How could I keep track of how many images there are? 如何跟踪有多少张图片?
  • How could I delete those images from the reference that are older than a week? 如何从参考中删除超过一周的图像?
  • Should I use Image Cashing Libraries like Kingfisher or would you go with the above style? 我应该使用像Kingfisher这样的Image Cashing库吗?还是您选择上述样式?

Thank you guys really much for any help! 非常感谢你们的帮助!

Let's handle these one at a time: 让我们一次处理这些:

  • What kind of way to name the images when users upload them would you suggest? 您建议用户使用哪种方式命名图像?

I'd take a look at the many other questions like this: Retrieving image from Firebase Storage using Swift 我将看一下其他许多这样的问题: 使用Swift从Firebase Storage检索图像

  • How could I keep track of how many images there are? 如何跟踪有多少张图片?

See above. 往上看。

  • How could I delete those images from the reference that are older than a week? 如何从参考中删除超过一周的图像?

You can use Object Lifecycle Management to delete images after a certain time. 您可以在一段时间后使用对象生命周期管理来删除图像。 Deleting them from the database would be harder--maybe an integration with Google Cloud Functions GCS notifications could sync this. 从数据库中删除它们会更加困难-可能是与Google Cloud Functions GCS的集成可以同步它。

  • Should I use Image Cashing Libraries like Kingfisher or would 我应该使用像Kingfisher这样的图像兑现库还是
    you go with the above style? 你选择上述风格吗?

I totally recommend using an image loader like SDWebImage or PINRemoteImage after pulling the download image from the realtime database. 我完全建议从实时数据库中提取下载图像后,使用SDWebImagePINRemoteImage之类的图像加载器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM