0

執行segue時,應用程序崩潰。我檢查是否有任何sigbrt錯誤,但沒有。我認爲這是日誌中的firebase分析。此錯誤來自日誌:preforming segue時的Firebase分析錯誤

以NSException類型的未捕獲異常終止。

代碼

@IBOutlet weak var email: UITextField! 
@IBOutlet weak var password: UITextField! 
@IBOutlet weak var adduser: UIButton! 
@IBOutlet weak var errormessege: UILabel! 

var databaseref = FIRDatabase.database().reference() 


override func viewDidLoad() { 
    super.viewDidLoad() 

    password.isSecureTextEntry = true 
    adduser.isEnabled = false 

} 

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






@IBAction func didtapadd(_ sender: Any) { 
    adduser.isEnabled = false 

    FIRAuth.auth()?.createUser(withEmail: email.text!, password: password.text!, completion: {(user,error) in 

     if error != nil { 

      if error!._code == 17999 { 
         self.errormessege.text = "Invalid email address" } 
      else { 

       self.errormessege.text = error?.localizedDescription 
      } 
     } 

     else 
     { 


      FIRAuth.auth()?.signIn(withEmail: self.email.text!, password: self.password.text!, completion: {(user,error) in 

       if (error == nil) { 


        self.databaseref.child("users").child(user!.uid).child("email").setValue(self.email.text!) 

        self.performSegue(withIdentifier: "hi", sender: nil) 



       } 
       else { 
        self.errormessege.text = error?.localizedDescription 

       } 
      }) 
     } 


    } 
    ) 


    } 



@IBAction func didtextchange(_ sender: Any) { 

     if((email.text?.characters.count)!>0){ 
     adduser.isEnabled = true} 
    else{ 
     adduser.isEnabled = false} 

} 
    @IBAction func did4(_ sender: Any) { 
    if((password.text?.characters.count)!>0){ 
     adduser.isEnabled = true} 
    else{ 
     adduser.isEnabled = false} 
} 
+0

您可以啓用火力地堡分析(添加-FIRAnalyticsDebugEnabled到您的應用程序在編輯計劃)調試模式,應用程序崩潰之前提供一些調試日誌?您的信息有限,因此很難判斷它是Firebase Analytics還是其他內容。 – adbitx

回答

0

沒有更多的代碼,並在我面前的整個方案就很難具體明確什麼是你的代碼和火力地堡之間發生的事情。有一件事可以顯着幫助你追蹤這個錯誤,即驗證你正在從你的@IBOutlets中抽出的每一步的數據。這樣,你的程序不會強制解開這些對象,而讓你的代碼面臨風險。

@IBOutlet weak var email: UITextField! 
@IBOutlet weak var password: UITextField! 
@IBOutlet weak var adduser: UIButton! 
@IBOutlet weak var errormessege: UILabel! 

var databaseref = FIRDatabase.database().reference() 

override func viewDidLoad() { 
    super.viewDidLoad() 
    password.isSecureTextEntry = true 
    adduser.isEnabled = false 
} 

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

@IBAction func didtapadd(_ sender: Any) { 
    adduser.isEnabled = false 

    guard let emailText = email.text, 
     let passwordText = password.text else { 
     // Handle error safely 
     print("Error unrapping email text or password text") 
     return 
    } 

    FIRAuth.auth()?.createUser(withEmail: emailText, password: passwordText, completion: { (user,error) in 

     if error != nil { 
      if error!._code == 17999 { 
       self.errormessege.text = "Invalid email address" 
      } else { 
       self.errormessege.text = error?.localizedDescription 
      } 
     } else { 
      FIRAuth.auth()?.signIn(withEmail: emailText, password: passwordText, completion: { (user, error) in 

       if (error == nil) { 
        guard let uid = user.uid else { 
         // handle error safely 
         print("Error with user uid") 
         return 
        } 
    self.databaseref.child("users").child(uid).child("email").setValue(emailText) 
        self.performSegue(withIdentifier: "hi", sender: nil) 
       } 
       else { 
        self.errormessege.text = error?.localizedDescription 

       } 
      }) 
     } 
    }) 
} 

@IBAction func didtextchange(_ sender: Any) { 

    guard let emailText = email.text else { 
     // Return error safely 
     print("Error unrapping email text") 
     return 
    } 

    if emailText.characters.count> 0 { 
     adduser.isEnabled = true 
    } else{ 
     adduser.isEnabled = false 
    } 
}