2016-08-03 78 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" 

       } 
      } 
} 
相關問題