简体   繁体   English

IOS:如何从 Firebase 实时数据库中的列表中获取特定的更改子项?

[英]IOS: How to get specific changed child from list in Firebase Realtime Database?

在此处输入图像描述

I have List of objects in firebase DB.我在 firebase DB 中有对象列表。 how to get specific child who changed in the list?如何获取列表中更改的特定孩子? Do I have made connection with every child?我和每个孩子都有联系吗?

Actually yes you have to do that.实际上是的,你必须这样做。 If you eg have users in there, you'll end up with something like this:如果你在那里有用户,你最终会得到这样的东西:

{
  users: {
    "user-0": {
      "firstName": "Max",
      "lastName": "Powers"
    },
    "user-1": {
      "firstName": "Maxime",
      "lastName": "Powers"
    }
  }
}

Now, from your apps perspective, the user is signed in and therefore the app knows the user-id.现在,从您的应用程序的角度来看,用户已登录,因此应用程序知道用户 ID。 With this information you can subscribe to changes on the whole user.使用此信息,您可以订阅整个用户的更改。

If you go one step further and nest eg rides below each user, as a mobility app will do, you end up with a JSON like this:如果您将 go 更进一步并在每个用户下方嵌套例如骑行,就像移动应用程序一样,您最终会得到一个 JSON,如下所示:

{
  users: {
    "user-0": {
      "rides": {
        "ride-0": {
          "updated_at": ...
        }
      }
    }
  }
}

When in this mobility app a user creates a ride, the app will will receive a ride-id from the backend which it can use to subscribe to the related ride in firebase.当用户在这个移动应用程序中创建行程时,该应用程序将从后端收到一个行程 ID,它可以使用它来订阅 firebase 中的相关行程。 The path would be eg users/<user-id>/rides/<ride-id> .路径例如是users/<user-id>/rides/<ride-id> The app will then get updates each time this ride is updted in the realtime database.每次在实时数据库中更新此行程时,该应用程序都会获得更新。

In the end each user has multiple subscriptions.最后,每个用户都有多个订阅。 We do it for a couple of years this way and it works quite well我们以这种方式做了几年,效果很好

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM