【问题标题】:Adding data to a specific UID in firebase将数据添加到 Firebase 中的特定 UID
【发布时间】:2016-12-09 03:03:16
【问题描述】:

我一直在尝试将用户输入的数据存储到他们在 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!])

【问题讨论】:

  • 有什么问题?
  • 我不知道如何在用户创建帐户时获得的唯一 uid 下将 xcode 中的文本字段中的数据存储到 firebase 实时数据库

标签: swift xcode firebase firebase-realtime-database


【解决方案1】:

假设用户已经在应用程序中通过身份验证,我已经设法解决了这个问题:为名为“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"

               }
            }
 }

【讨论】:

    猜你喜欢
    • 2021-12-24
    • 1970-01-01
    • 2022-10-14
    • 1970-01-01
    • 2023-03-06
    • 2020-10-10
    • 2017-07-30
    • 2018-07-05
    • 1970-01-01
    相关资源
    最近更新 更多