2016-08-03 77 views
1

我一直试图将用户输入的数据存储到他们在firebase中的个人用户id,但到目前为止,只有当用户创建帐户时才能做到这一点,了解如何将数据从xcode中的文本字段存储到唯一用户ID下的Firebase实时数据库,用户在创建帐户时获得的数据?将数据添加到Firebase中的特定UID

例如:我有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

是什么问题? – iOSGeek

+0

我不知道如何将数据从xcode中的文本字段存储到用户在创建帐户时获取的唯一用户ID下的Firebase实时数据库 – crispy2k12

回答

1

我已经设法解决这个问题,假设用户在应用中已经证实:创建一个IBOutlet一个名为“yourtextfieldname”文本字段的数据转换成一个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" 

       } 
      } 
} 
相关问题