将数据添加到Firebase中的特定UID [英] Adding data to a specific UID in firebase

查看:52
本文介绍了将数据添加到Firebase中的特定UID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试将用户输入的数据存储到Firebase中的个人uid,但是到目前为止,我只能在用户创建帐户后才能执行此操作,而我试图找出的是如何存储数据从xcode的文本字段到唯一的uid下的firebase实时数据库,用户在创建帐户时会得到它?

i've been trying to store user inputted data to the their personal uid in firebase but so far i've only been able to do this when the user created an account and what im trying to find out is how to store data from a text field in xcode to the firebase realtime database under a unique uid, that the user gets when they create an account??

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

for example: i have 3 textfields that will store the user information to the already assigned UID when they created the account at the start of the application.

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参数中.然后将该功能添加到按钮操作中.

I've managed to solve the problem, assuming the user is already authenticated within the application: create an IBoutlet for the textfield named "yourtextfieldname" convert the textfield data into an NSSTRING and place the otherstr variable in the setValue parameter. then add the function to the button action.

   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"

               }
            }
 }

这篇关于将数据添加到Firebase中的特定UID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆