ios - 在 Firebase 上创建用户时设置值 - Swift

标签 ios json swift firebase

我正在尝试在 Firebase 中创建用户并在创建用户时保存用户信息。这是我创建用户的操作函数:

@IBAction func createAccountButton(_ sender: AnyObject) {

            FIRAuth.auth()?.createUser(withEmail: emailTextField.text!, password: passwordTextField.text!, completion: { (user, error) in
                if error != nil {
                    print(error!.localizedDescription)
                } else {
                    let userID =  (user?.uid)! as String
                    self.bringerUser.userRef = userID as String
                    let userEmail:String = self.emailTextField.text!
                    print(userEmail)
                    print(self.bringerUser.userRef! as String)
                    self.ref.child("users").child(self.bringerUser.userRef! as String).child("userInfo").setValue(["email": emailTextfield.text])
                }
            })
    }

尝试在 Firebase 上访问和写入数据时,用户 ID 为 nil,但如果我打印它,它工作正常。我得到的错误是这样的:

fatal error: unexpectedly found nil while unwrapping an Optional value

最佳答案

尝试:-

FIRDatabase.database().reference().child("users").child(FIRAuth.auth()!.currentUser!.uid).child("userInfo").setValue(["email": emailTextfield.text])

关于ios - 在 Firebase 上创建用户时设置值 - Swift,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40390495/

相关文章:

ios - 供应配置文件不包括应用程序标识符和钥匙串(keychain)访问组权利

ios - 否定#available语句

java - Json 数据分配给 java 类

ios - 为 sprite 节点分配 Int 值

ios - 将联系人地址保存到统一联系人会导致(CNErrorDomain 错误 500)

ios - TableView 单元格中的 ScrollView 将无法正确显示图像,并且 swift 4 中的分页模式下有一页额外的页面

ios - 如何在不关闭父/第一个 View Controller 的情况下以模态方式呈现 View Controller

java - 无法解析 JSON 数据

java - 创建一个没有 key 的 JSON

ios - Xcode MyProjectName-Bridging-Header.h 不存在