Ios 未将数据插入Swift 3中Firebase中用户UID的节点下

Ios 未将数据插入Swift 3中Firebase中用户UID的节点下,ios,firebase,swift3,firebase-realtime-database,firebase-authentication,Ios,Firebase,Swift3,Firebase Realtime Database,Firebase Authentication,当我在userID下保存数据时,数据没有存储到Firebase中,并且在展开可选值时意外地发现错误为零,但是当我使用childByAutoID时,数据被成功存储。帮助我保存在userID节点下。在这里,我已经解释过,当我在注册操作下创建用户时,这种情况正在发生 @IBAction func createAccountAction(_ sender: Any) { if self.emailTextField.text == "" || self.passwordTextField.te

当我在
userID
下保存数据时,数据没有存储到Firebase中,并且在展开可选值时意外地发现错误
为零,但是当我使用
childByAutoID
时,数据被成功存储。帮助我保存在
userID
节点下。在这里,我已经解释过,当我在注册操作下创建用户时,这种情况正在发生

@IBAction func createAccountAction(_ sender: Any) {

    if self.emailTextField.text == "" || self.passwordTextField.text == "" {
        let alertController = UIAlertController(title: "Error", message: "Please enter your email and password", preferredStyle: .alert) 
        let defaultAction = UIAlertAction(title: "OK", style: .cancel, handler: nil)
        alertController.addAction(defaultAction) 
        present(alertController, animated: true, completion: nil)   
    } else if (self.passwordTextField.text != self.retypePasswordfield.text) {
        let alertController = UIAlertController(title: "Error", message: "Password does not match", preferredStyle: .alert)
        let defaultAction = UIAlertAction(title: "OK", style: .cancel, handler: nil)
        alertController.addAction(defaultAction) 
        present(alertController, animated: true, completion: nil)
    } else {
        ref.child("user_registration").setValue(["username": self.fullName.text, "email": self.emailTextField.text,"contact": self.numberText.text, "city": self.myCity.text, "state": self.countryText.text, "gender": genderGroup, "blood": bloodGroup])

        FIRAuth.auth()?.createUser(withEmail: emailTextField.text!, password: passwordTextField.text!) { (user, error) in

            if error == nil {
                FIRAuth.auth()?.currentUser!.sendEmailVerification(completion: { (error) in
                })  
                print("You have successfully signed up")
                let alertController = UIAlertController(title: "Successful!", message: "Email Verification link sent", preferredStyle: .alert)
                let alertActionOkay = UIAlertAction(title: "Okay", style: .default) { (action) in
                    let vc = self.storyboard?.instantiateViewController(withIdentifier: "LoginFirstViewController")
                    self.present(vc!, animated: true, completion: nil)
                }
                alertController.addAction(alertActionOkay)
                self.present(alertController, animated: true, completion: nil)
            } else {
                let alertController = UIAlertController(title: "Error", message: error?.localizedDescription, preferredStyle: .alert)
                let defaultAction = UIAlertAction(title: "OK", style: .cancel, handler: nil)
                alertController.addAction(defaultAction)
                self.present(alertController, animated: true, completion: nil)
            }
        }
    }
 }

仅供参考

这是我目前的工作代码

注册按钮

 // Create new User
            FIRAuth.auth()?.createUser(withEmail: self.tfEmail.text!, password: self.tfPassword.text!, completion: { (user, error) in

                if error == nil{ // IF NO ERROR

                    let astrContact = self.strDialCode + " " + self.tfMobileNumber.text!

                    // Dict to add user data in firebase Db
                    let aDBDict : [String : String] = ["userName": self.tfFullName.text!,
                                                       "userEmail": self.tfEmail.text!,
                                                       "userContact": astrContact,
                                                       "userCountry": self.strCode,
                                                       "userID": (user?.uid)!]


                    // Add data in DB
                    ref?.child("Customer/\(String(describing: (user?.uid)!)/userProfileDetails").setValue(aDBDict)

                    DispatchQueue.main.async(execute: { () -> Void in

                        // goto home VC
                        let storyboard = UIStoryboard(name: "Main", bundle: nil)
                        let navController = storyboard.instantiateViewController(withIdentifier: "MainController")

                        if let window = AppDelegate.getAppDelegate().window {
                            window.rootViewController = navController
                        }
                    })
                }
                else{ // If error in creating new user
                    print("error in creating new user")
                    print(error!)
                }
            })
在appDelegate中

extension AppDelegate {

    class func getAppDelegate() -> AppDelegate {
        return UIApplication.shared.delegate as! AppDelegate
    }
}

您的用户未经身份验证,因此首先对其进行身份验证。这可能是个问题。因为它不会获取当前用户。为了帮助您进行调试,您可以将这样的行拆分为多个部分,以便查看错误发生的位置。将uid提取到一个变量中,定义引用,提取textfield数据,然后将其全部放在一起。这就是说,正如@dahiya_boy所建议的,你应该总是从你正在展开的任何东西开始,而且看起来当前用户并不是这样authenticated@dahiya_boy用户正在注册,因此用户未注册authenticated@Russell用户正在注册,因此用户未经过身份验证,我已经做了和你说的一样的事情,但仍然有同样的错误,因为用户是注册的。有什么建议吗?您应该在Auth delegate方法中调用此方法。其中一个将在用户成功注册后告诉您usergetAppDelegate()未定义?appdelegate的值没有成员
userdetails
appdelegate的值没有成员
uID
我删除了一些与您无关的代码工作。这些是在AppDelegate中声明的变量。所以使用新编辑的代码。你知道这个变量吗?