我是使用Firebase的新手,我正在使用Firebase登录并注册应用程序的窗口。

现在,只要我从控制台创建帐户,登录就可以正常工作
This is what the login code looks like

但是,如果您想创建一个新帐户,请单击该按钮,然后将您带到新的Viewcontroller窗口,在那儿我添加了一些东西来填充以创建一个新帐户,并且我使用了

FIRAuth.auth()?.createUserWithEmail(<email: String>, password: <String>, completion: <FIRAuthResultCallback?(FIRUser?, NSError?) -> Void#>)

这里是代码外观的图片
picture of the code and the imageview

当我尝试注册新用户时,我收到“无效”消息,我真的不知道为什么它没有创建新用户

奖金问题
当我使它工作时,如何使它从那个窗口转到另一个窗口?

最佳答案

这应该工作:

var ref: FIRDatabaseReference!


override func viewDidLoad() {
    super.viewDidLoad()

    ref = FIRDatabase.database().reference()
    // Do any additional setup after loading the view.
}


@IBAction func signup(sender: AnyObject) {
    if let em = email.text, pass = password.text{
        FIRAuth.auth()?.createUserWithEmail(email.text!, password: password.text!) {(user, error) in
            if let error = error {
                print(error.localizedDescription)
            }
            else {
                print("User signed in!")

                self.ref.child("data/users").updateChildValues(["\(FIRAuth.auth()!.currentUser!.uid)":["Username":self.username.text!]])

                self.performSegueWithIdentifier("home", sender: self)
                //At this point, the user will be taken to the next screen
            }
        } }
    else{
        print("You left email/password empty")
    }
}

确保同时安装了Firebase,FirebaseAuth和FirebaseDatabase(如果您使用的是cocoapods,则您的Pod应该如下图所示)
pod 'Firebase'
pod 'Firebase/Auth'
pod 'Firebase/Database'

07-27 14:04