xcode 无法使用 Firebase 身份验证:FIRAuth.auth 不起作用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/44559027/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 10:03:07  来源:igfitidea点击:

Cannot use Firebase authentication: FIRAuth.auth does not work

iosswiftxcodefirebase

提问by Andrew Qin

I have been struggling with this issue for a few days, I am a rookie and I am not able to find a solution. I am trying to create a user sign up and log in page using XCode 8.3.3 and am using Firebase as database.

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

My code is as follows:

我的代码如下:

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) 
            }
        }
    }   
}

The part that has issue is FIRAuth.auth. The error says "FIRAuthhas been renamed to Auth" and if I applied such fix, although the built became successful, I could only see nothing but a white screen. If I delete the code then I can see a normal sign in screen created earlier.

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

Another thing is when I type import FirebaseAutha red line appeared in the suggested word list that crossed out FirebaseAuth, I still proceeded.

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

Please help. I don't know why it happens. Could there be any missing pod files? Much appreciated.

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

Storyboard: storyboard

故事板: 故事板

回答by Vlad Pulichev

FIRAuthbecame a Authin last Firebaseversion. link to Docs

FIRAuth成为Auth最后一个Firebase版本。链接到文档

import Firebase

Then, in the application:didFinishLaunchingWithOptions:method, initialize the FirebaseAppobject:

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

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

Now you can use in your file (also import Firebase)

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

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

Hope it helps

希望能帮助到你

回答by Kiran

You need to put this line into your pod file- pod 'Firebase/Auth'. do pod install after and you should be able to do get rid of the errors regarding Auth.

您需要将此行放入您的 pod 文件 - pod 'Firebase/Auth'。在之后执行 pod install,您应该能够摆脱有关 Auth 的错误。