[英]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 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”
Thank you guys really much for any help! 非常感谢你们的帮助!
Let's handle these one at a time: 让我们一次处理这些:
I'd take a look at the many other questions like this: Retrieving image from Firebase Storage using Swift 我将看一下其他许多这样的问题: 使用Swift从Firebase Storage检索图像
See above. 往上看。
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的集成可以同步它。
I totally recommend using an image loader like SDWebImage or PINRemoteImage after pulling the download image from the realtime database. 我完全建议从实时数据库中提取下载图像后,使用SDWebImage或PINRemoteImage之类的图像加载器。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.