我尝试让function
让用户在使用application
之前从 Firebase 下载所有内容,这是可选的。它应该使用户体验更好。可能吗?
现在我的JSON
包含这些字段。 JSON实际上要长得多:
"Snuses" : {
"Catch Eucalyptus White Large" : {
"Brand" : "Catch",
"Products" : "Catch Eucalyptus White Large",
"PorionWeight" : 21.6,
"flavor" : "Tobacco, Eucalyptus",
"nicotine" : 8.0,
"PortionsCan" : 24,
"shipping weight" : 39,
"productUrl" : "https://firebasestorage.googleapis.com/v0/b/snuspedia.appspot.com/o/Catch%20Dry%20Eucalyptus%20White%20Mini.png?alt=media&token=b712f44c-a83b-4a18-b9cc-7f77897e5489"
},
我还使用Firebase存储,其中包含有关(20mb
)的图像。我想parse
所有的信息+图像,然后完成后再显示它们。
现在我正在为图像这样做:
if productsValue[indexPath.row]["productUrl"] != nil {
cell.snusProductImageView!.kf_setImageWithURL(NSURL(string: productsValue[indexPath.row]["productUrl"] as! String)!)
}
else {
let productImageref = productsValue[indexPath.row]["Products"] as! String
let decomposedPath = productImageref.decomposedStringWithCanonicalMapping
cell.snusProductImageView.image = nil
cell.snusProductImageView.kf_showIndicatorWhenLoading = true
FIRStorage.storage().reference().child("\(decomposedPath).png").downloadURLWithCompletion({(url, error)in
FIRDatabase.database().reference().child("Snuses").child(decomposedPath).child("productUrl").setValue(url!.absoluteString)
let resource = Resource(downloadURL: url!, cacheKey: decomposedPath)
cell.snusProductImageView.kf_setImageWithURL(url)
})
对于所有其他内容几乎相同。
这样做最好的选择是什么?
答案 0 :(得分:0)
我刚刚遇到了类似的问题,当我希望我的IOS应用程序在启动之前下载所有Firebase数据以提高用户性能时,我的解决方案是使用本地数据库来存储数据。
我个人选择Realm是因为它易于实现和使用,但还有许多其他可用选项,如Core Data或SQLite。
但是,我的解决方案只能解决您问题的一半,因为您还需要存储大量图像。我还没有处理存储如此大量的图像,因此我无法就此提供建议。除了图像,Realm将为您存储剩余的数据。