当按下按钮时,应用程序崩溃,并显示与Firebase相关的错误

时间:2019-07-09 19:25:04

标签: ios swift firebase swift4.2 swift5

在阅读所有这些内容之前,很长的帖子对不起,但是我想尽我所能地解释这种情况,因为我无法在线找到类似的错误。

大家好,我正在快速制作此应用,它的主屏幕带有“ loginButton”和“ signUp”

我在一个常规文件上制作了所有应用程序屏幕及其限制,然后安装了一些Pod。

pod 'Firebase'
pod 'Firebase/Auth'
pod 'Firebase/Database'
pod 'GoogleMaps'
pod 'GooglePlaces'

之后,我开始配置“注册”和“登录View”控制器以与Firebase通信。

注册很好,但是当我完成登录后,发生了一些事情。

每次我单击“ loginButton”时,我的应用都会由于没有明显的原因而崩溃(对我而言,我并没有那么快,而且仍然有很多无法识别的错误)

它给我的错误是“ [I-ACS036002]分析屏幕报告已启用。调用+ [FIRAnalytics setScreenName:setScreenClass:]设置屏幕名称或覆盖默认屏幕类名称。要禁用屏幕报告,请设置在Info.plist中将FirebaseScreenReportingEnabled标记为NO(布尔值)”

但是对我来说,这似乎不是问题所在,因为Firebase不会给我任何SignUp错误,这很奇怪,因为两个按钮的配置都相同。

我非常渴望获得帮助,因此如果您需要查看一些代码或其他内容,请告诉我,我将其发布。

我已经尝试删除从主屏幕到登录屏幕的按钮设置,并且错误仍在继续。

已经删除了我已经完成的LoginViewController,以查看它是否真的是我犯错的任何Firebase配置,但是错误仍然存​​在,并且在该视图控制器上我没有使用Firebase

并且显然已经做了Xcode在错误中建议的“要禁用屏幕报告,请将Info.plist中的FirebaseScreenReportingEnabled标志设置为NO(布尔值)”,并且该错误仍然存​​在。那个时候出现了一个不同的错误,该错误基本上只是告诉我我已将其禁用,并且该应用无法像这样运行。

我可以向您展示“注册”视图控制器代码,因为它与“登录”代码相同。

import UIKit
import Firebase

class SignInViewController: UIViewController, UITextFieldDelegate {


    @IBOutlet weak var emailTextfield: UITextField!
    @IBOutlet weak var passwordTextField: UITextField!
    @IBOutlet weak var dismissButton: UIButton!


    var signupButton:UIButton!
    var activityView:UIActivityIndicatorView!

    override func viewDidLoad() {
        super.viewDidLoad()

        //Botão de Login Programatico porque o do desgin estava a dar demasiados problemas... tipo que este não vai dar, lol
        signupButton = RoundedWhiteButton(frame: CGRect(x: 0, y: 0, width: 200, height: 50))
        signupButton.setTitle("Log In", for: .normal)
        signupButton.titleLabel?.font = UIFont.systemFont(ofSize: 18.0, weight: UIFont.Weight.bold)
        signupButton.setTitleColor(textColor, for: .normal)
        signupButton.center = CGPoint(x: view.center.x, y: view.frame.height - signupButton.frame.height - 24)
        //Evento HandleLogin
        signupButton.addTarget(self, action: #selector(handleSignup), for: .touchUpInside)
        signupButton.alpha = 0.5
        //Adicionar à view e chamar função "setLoginButton"
        view.addSubview(signupButton)
        setSignupButton(enabled: false)

        //Rodinha bonita que aparece no signupButton quando os dados estão a ser processados, só para não usar mais um CocoaPod
        activityView = UIActivityIndicatorView(style: .gray)
        activityView.frame = CGRect(x: 0, y: 0, width: 50.0, height: 50.0)
        activityView.center = signupButton.center

        view.addSubview(activityView)

        //já são meninos crescidos, já podem tomar conta de si mesmos.
        emailTextfield.delegate = self
        passwordTextField.delegate = self
        //estava a brincar. isto é para esta brincadeira funcionar como deve de ser xisdê
        emailTextfield.addTarget(self, action: #selector(textFieldChanged), for: .editingChanged)
        passwordTextField.addTarget(self, action: #selector(textFieldChanged), for: .editingChanged)


        //coias bonitas para as "notificações" do teclado
        NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillShow), name: UIResponder.keyboardWillShowNotification, object: nil)
        NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillHide), name: UIResponder.keyboardWillHideNotification, object: nil)

        // Do any additional setup after loading the view.
    }

    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        emailTextfield.becomeFirstResponder()
    }


    //Evento "touchUpInside" no dismissButton, faz com que a view volte para o ecrã principal

    @IBAction func handleDismissButton(_ sender: Any) {
        self.dismiss(animated: true, completion: nil)
    }

    //MARK: Funções

    //MARK: keyboardWillShow
    //recebe uma notificação quando o teclado "aparece", permitindo que o signupButton seja deslocado mais para cima, impedindo-o de ficar escondido atrás do teclado.
    @objc func keyboardWillShow(notification: NSNotification) {
        let info = notification.userInfo!
        let keyboardFrame: CGRect = (info[UIResponder.keyboardFrameEndUserInfoKey] as! NSValue).cgRectValue

        signupButton.center = CGPoint(x: view.center.x,
                                     y: view.frame.height - keyboardFrame.height - 16.0 - signupButton.frame.height / 2)
        activityView.center = signupButton.center

    }

    //MARK: keyboardWillHide
    //recebe uma notificação quando o teclado "desaparece", permitindo que o signupButton seja deslocado para a sua posiçao inicial.
    @objc func keyboardWillHide(notification: NSNotification){
        signupButton.center = CGPoint(x: view.center.x, y: view.frame.height - signupButton.frame.height)
        activityView.center = signupButton.center
    }

    //MARK: setLoginButton
    //Se o resultado for verdadeiro, o botão fica ativo e sem transparencia.
    func setSignupButton(enabled:Bool) {
        if enabled {
            signupButton.alpha = 1.0
            signupButton.isEnabled = true
        } else {
            signupButton.alpha = 0.5
            signupButton.isEnabled = false
        }
    }

    //Nem sei muito bem, ainda estou para descobrir, mas isto de alguma maneira faz com que o botão "log in" fique ativo

    @objc func textFieldChanged(_ target:UITextField) {
        let email = emailTextfield.text
        let password = passwordTextField.text
        let formFilled = email != nil && email != "" && password != nil && password != ""
        setSignupButton(enabled: formFilled)
    }

    //evento que dá handle ao evento "touchUpInside" do "signupButton"
    @objc func handleSignup() {

        setSignupButton(enabled: false)
        signupButton.setTitle("", for: .normal)
        activityView.startAnimating()

        Auth.auth().createUser(withEmail: emailTextfield.text!, password: passwordTextField.text!) { (user,error) in
            if error != nil{
                print(error!)
            } else {
                print("Registration Successful!")            
                self.performSegue(withIdentifier: "goToMap", sender: self)
            }

        }




    }

}

如果有谁能帮助我,我将非常感激,我现在​​需要该应用程序做的就是按预期工作,在用户输入凭据后将登录名重定向到主应用程序屏幕。< / p>

预先感谢

0 个答案:

没有答案