Swift更多信息创建用户

时间:2018-07-19 13:11:09

标签: swift firebase firebase-authentication

你好,我希望当用户创建一个帐户时,他还必须在注册中写上他的全名,电话号码...但是我只有这个代码... 我如何将全名和电话号码整合到注册中 谢谢您的帮助

class SignUpViewController: UIViewController {


    @IBOutlet weak var userNameTextField: UITextField!
    @IBOutlet weak var userPhoneNumberTextField: UITextField!
    @IBOutlet weak var userEmailTextField: UITextField!
    @IBOutlet weak var userPasswordTextField: UITextField!
    @IBOutlet weak var confirmuserPasswordTextField: UITextField!


    private var authUser : User? {
        return Auth.auth().currentUser
    }

    public func sendVerificationMail() {
        if self.authUser != nil && !self.authUser!.isEmailVerified {
            self.authUser!.sendEmailVerification(completion: { (error) in
                // Notify the user that the mail has sent or couldn't because of an error.
            })
        }
        else {
            // Either the user is not available, or the user is already verified.
        }
    }

    @IBAction func signupButtonTapped(_ sender: Any) {
        print("Sign up button tapped")


        Auth.auth().createUser(withEmail: self.userEmailTextField.text!, password: self.userPasswordTextField.text!) { (user, error) in
            if user != nil {
              print("User has Signed Up")


                self.sendVerificationMail()
                self.performSegue(withIdentifier: "ToVerify", sender: nil)

            }
            if error != nil {
                print("User cant Sign Up")
            }
        }


}

1 个答案:

答案 0 :(得分:0)

您可以在对Firebase身份验证的单独调用中设置用户的显示名称(以及需要的照片URL)。来自Firebase documentation

let changeRequest = Auth.auth().currentUser?.createProfileChangeRequest()
changeRequest?.displayName = displayName
changeRequest?.commitChanges { (error) in
  // ...
}

据我所知,phone number in a user profile仅在您使用phone number verification时保留。没有办法自己设置它。

如果您只想存储数字,请考虑使用其他存储机制,例如Firebase实时数据库或Cloud Firestore。请参阅以前的questions on storing additional user data中的一些内容。