gpt4 book ai didi

ios - Firebase 上的好友列表

转载 作者:搜寻专家 更新时间:2023-11-01 07:22:36 24 4
gpt4 key购买 nike

到目前为止,在我的 firebase 上,我有类似的东西:

Users
293840ajldkjfas0d9
username: Jill
09283049802930laks
username: Jack

我基本上只有一个文本字段,当有人点击“添加”按钮时,通过 firebase 进行搜索以确保用户名存在,然后从那里开始将两者连接为 friend 。

我的问题是,如果数据的结构如此,我不明白我将如何对数据进行排序?我可能完全遗漏了一些东西,但有没有办法搜索我现在拥有的内容并说“转到我的用户引用,转到每个 UID 并提取用户名,看看它是否与用户在文本字段中输入的内容匹配,如果是,则获取连接到用户名的 UID"?

我几乎在想我需要有一个完全独立的分支吗?除了我已经拥有的东西之外,我还拥有看起来像的东西

Usernames
Jack
09283049802930laks
Jill
lasdjf9j09u90320j09

这样我就可以转到我的用户名并检查其中的值 (jack/Jill),然后如果它存在,则将该 uid 从用户名中拉出。

1) 我是否需要这两个分支,或者有没有办法只用我的第一个分支来完成我想做的事情?

2) 我究竟如何检查该匹配项?是使用查询还是仅以某种方式检查 Null?

3) 这甚至是正确的方法吗?我在网上的好友列表上几乎找不到任何信息,所以这只是一个假设。

感谢任何帮助!

最佳答案

Using the below structure, you can check if a user exists with a single query. Here's all the code you need:

这是数据库结构:

Users
293840ajldkjfas0d9
username: Jill
09283049802930laks
username: Jack

代码如下:

    var usernameEntered = self.usernameField.text!

var databaseReferenceQuery = self.ref.child("users").queryOrderedByChild("username").queryEqualToValue(usernameEntered).observeSingleEventOfType(.Value, withBlock: { (snapshot) in

if ( snapshot.value is NSNull ) {



// No user :(



} else {

// User exists! Do stuff!


}


}, withCancelBlock: { (error) in

// An error occurred
})

一旦确定用户存在,我可以想出几种方法来获取 uid。关键是要找到一个同时存放uid和用户名的地方。

选项 1:

Create another branch in the users db structure that stores the uid. Set up this branch when the user is signed up.

选项 2:

Store the username as the displayName in the standard auth system and get the uid from there. Set this up when the user signs up.

这取决于你。

Response to comments: You can simply retrieve the key of the user in the table, however this will not allow access to any auth features and will not allow user accounts to be edited in any way.
Examples of situations where this can be useful include updating user info, deleting accounts etc.

关于ios - Firebase 上的好友列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37978398/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com