我一直在尝试将用户输入的数据存储到他们在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!])
答案 0 :(得分:2)
我设法解决了这个问题,假设用户已经在应用程序中进行了身份验证:为名为" 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"
}
}
}