【问题标题】:Firebase does not update values throughout an app until the user is logged out在用户注销之前,Firebase 不会在整个应用中更新值
【发布时间】:2017-04-23 15:24:54
【问题描述】:

因此,我遇到了一个问题,即我的 Firebase 应用在用户进行更新时不会更新用户值。更清楚地说:假设用户 1 有一张狗的照片,然后将其更改为猫。

一旦他们将其更改为猫,我在 Firebase 中的节点值将成功更新,但用户自己将无法看到应用中其他先前加载的区域(其他有狗图片的地方)的变化,直到他们注销然后重新登录。

出于这个原因,我想知道是否有任何方法可以执行后台应用程序刷新,这样应用程序中所有以前的狗值都将更改为猫值,而无需用户注销然后重新登录。请注意同样的问题不仅发生在我用户的个人资料图片上,而且发生在我设置的任何其他用户字段上。

这是我在 Firebase 中为我的用户更新节点值的方式:

        let storageRef = FIRStorage.storage().reference()
        _ = FIRStorageMetadata()
        let filePath = "\(FIRAuth.auth()?.currentUser?.uid)/\("userPhoto")"
        let profileImageData = UIImageJPEGRepresentation(self.profilePicture.image!, 1.0)

        if let data = profileImageData {
            storageRef.child(filePath).put(data, metadata: nil){(metaData,error) in
                if let error = error {
                    print(error.localizedDescription)
                    return
                } else {

                    let downloadURL = metaData!.downloadURL()!.absoluteString

                    let userPhotoUpdateRef = FIRDatabase.database().reference().child("users").child(self.currentUser).child("userPhoto")
                    userPhotoUpdateRef.setValue(downloadURL)
                }
            }
        }

如果您有任何问题,请提出!任何帮助将不胜感激!

【问题讨论】:

    标签: ios swift firebase firebase-storage


    【解决方案1】:

    适用于云存储的 Firebase SDK 提供了一种从云存储读取文件和将文件写入云存储的简单方法。它不提供监控这些文件的方法。

    提供监控方法的最简单方法是将文件的元数据写入 Firebase 实时数据库。请参阅存储文档中的简短部分以简要说明这一点:https://firebase.google.com/docs/storage/ios/file-metadata#custom_metadata

    当您将数据写入 Firebase 数据库中的某个位置时,所有actively monitoring that location 的应用都会立即更新。当他们获得该更新时,您可以从 Cloud Storage for Firebase 重新加载图像。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-04-30
      • 2019-08-12
      • 2021-12-09
      • 1970-01-01
      • 2020-09-10
      • 2019-11-18
      • 2015-07-03
      • 2019-07-09
      相关资源
      最近更新 更多