我一直在尝试将用户输入的数据存储到Firebase中的个人uid,但是到目前为止,我只能在用户创建帐户时才能执行此操作,而我试图找出的是如何从文本中存储数据用户在创建帐户时获得的唯一uid下的xcode中的字段到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"
}
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句