【问题标题】:Give user option to download all content from Firebase为用户提供从 Firebase 下载所有内容的选项
【发布时间】:2016-08-28 11:17:22
【问题描述】:

我正在尝试使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)

            })

所有其他内容几乎相同。

最好的选择是什么?

【问题讨论】:

    标签: json swift uitableview firebase


    【解决方案1】:

    前段时间我遇到了和你类似的问题,当时我希望我的 IOS 应用程序在启动前下载所有 Firebase 数据以提高用户性能,我的解决方案是使用本地数据库来存储数据。

    我个人选择 Realm 是因为它易于实现和使用,但还有许多其他可用选项,例如 Core Data 或 SQLite。

    但是,我的解决方案只能解决一半的问题,因为您还要存储大量图像。我还没有处理存储这么大量的图像,所以我不能给你建议。除了图像,Realm 会很好地为您存储其余数据。

    【讨论】:

    • 我的内容也在更新中。
    猜你喜欢
    • 1970-01-01
    • 2017-09-18
    • 2012-02-18
    • 1970-01-01
    • 2015-03-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多