gpt4 book ai didi

swift - 将数据添加到 firebase 中的特定 UID

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

我一直在尝试将用户输入的数据存储到他们在 firebase 中的个人 uid,但到目前为止,我只能在用户创建帐户时执行此操作,而我想知道的是如何存储数据从 xcode 中的文本字段到用户在创建帐户时获得的唯一 uid 下的 firebase 实时数据库?

例如:我有 3 个文本字段,当用户在应用程序开始时创建帐户时,它们会将用户信息存储到已分配的 UID 中。

let uid = user.uid
ref.child("users").child(user!.uid).setValue(["DOB": self.DOB. text!,
"Address": self.address.text!, "age":self.age.text!])

最佳答案

假设用户已经在应用程序中通过身份验证,我已经设法解决了这个问题:为名为“yourtextfieldname”的文本字段创建一个 IBoutlet 将文本字段数据转换为 NSSTRING 并将 otherstr 变量放在 setValue 参数中。然后将函数添加到按钮操作。

   let userID = FIRAuth.auth()?.currentUser?.uid
//gets current user uid

func test() {

let str = yourtextfieldname.text
let otherstr = str! as NSString
//convert textfield datatype NSString

self.ref.child("users").child(userID!).child("yourtextfieldname").setValue(otherstr)

}

@IBAction func but(sender: AnyObject) {
//calling test function
updateProfile()


}

Json数据结构

{
"users": {
"unique UID": {
"test": "strTest"

}
}
}

关于swift - 将数据添加到 firebase 中的特定 UID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38742782/

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