我正在尝试使用 Firebase 存储实现图像提要,可以将其视为 Instagram 照片提要。 我的问题:
- 我不知道我的 Firebase 引用文件夹中有多少张图片
- 我只想显示已拍摄的图像,比方说在上周
我试过像这样从引用资料中下载图片:
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
}
})
}
在这里我遇到了一个明显的问题:我只下载了 10 张图片,名为“1”、“2”、...、“10”
- 当用户上传图片时,您建议采用哪种命名方式?
- 我如何跟踪有多少张图片?
- 如何从引用中删除那些超过一周的图片?
- 我应该使用像 Kingfisher 这样的 Image Cashing Libraries 还是你会选择上面的风格?
非常感谢你们的帮助!
最佳答案
让我们一次处理这些:
- 当用户上传图片时,你会用什么样的方式命名图片? 建议?
我会像这样查看许多其他问题:Retrieving image from Firebase Storage using Swift
- 我如何跟踪有多少张图片?
见上文。
- 我怎样才能从引用中删除那些早于 周?
您可以使用 Object Lifecycle Management一定时间后删除图像。从数据库中删除它们会更难——也许与 Google Cloud Functions GCS notifications 集成可以同步这个。
- 我应该使用 Kingfisher 之类的图像缓存库还是
你喜欢上面的风格吗?
我完全推荐使用像 SDWebImage 这样的图像加载器或 PINRemoteImage从实时数据库中拉取下载图像后。
关于iOS/swift : How to manage image downloading from Firebase in a feed,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39440063/