无法使用Firebase身份验证:FIRAuth.auth无效

时间:2017-06-15 05:12:39

标签: ios swift xcode firebase

我已经在这个问题上苦苦挣扎了几天,我是一个新手,我无法找到解决方案。我正在尝试使用XCode 8.3.3创建用户注册和登录页面,并使用Firebase作为数据库。

我的代码如下:

import UIKit
import Firebase
import FirebaseAuth

class SignUpViewController: UIViewController {

    //Outlets
    @IBOutlet weak var emailTextField: UITextField!
    @IBOutlet weak var passwordTextField: UITextField!

    //Sign Up Action for email
    @IBAction func createAccountAction(_ sender: AnyObject) {

        if emailTextField.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 {
            FIRAuth.auth().createUser(withEmail: emailTextField.text!, password: passwordTextField.text!) { (user, error) in

            if error == nil {
                print("You have successfully signed up")
                //Goes to the Setup page which lets the user take a photo for their profile picture and also chose a username

                let vc = self.storyboard?.instantiateViewController(withIdentifier: "Home")
                self.present(vc!, 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) 
            }
        }
    }   
}

有问题的部分是FIRAuth.auth。错误说“FIRAuth已经重命名为Auth”,如果我应用了这样的修复,虽然内置成功,但我只能看到白屏。如果我删除了代码,那么我可以看到之前创建的普通登录屏幕。

另一件事是,当我输入导入FirebaseAuth时,建议的单词列表中出现了一条划掉FirebaseAuth的红线,我仍然继续。

请帮忙。我不知道为什么会这样。可能有任何丢失的pod文件?非常感谢。

故事板: storyboard

2 个答案:

答案 0 :(得分:6)

FIRAuth在过去Auth版本中成为Firebaselink to Docs

import Firebase

然后,在application:didFinishLaunchingWithOptions:方法中,初始化FirebaseApp对象:

// Use Firebase library to configure APIs
FirebaseApp.configure()

现在您可以在您的文件中使用(也是import Firebase

Auth.auth().createUser(withEmail: email, password: password) { (user, error) in
    // ...
}

希望有所帮助

答案 1 :(得分:0)

您需要将此行放入您的pod文件-pod'Firebase / Auth'。在完成Pod安装之后,您应该可以摆脱与Auth有关的错误。

相关问题