简体   繁体   English

Swift + Firebase模拟登录错误

[英]Swift + Firebase simulated login error

iOS rookie here struggling through the early stages of an app that was initially led by a mentor. iOS新秀在最初由导师领导的应用程序的早期阶段苦苦挣扎。 Issue at the moment occurs in the login view controller: 当前在登录视图控制器中出现的问题:

                override func viewDidAppear(animated: Bool) {
                super.viewDidAppear(animated)
                let myRootRef = Firebase(url:"https://xxxx.firebaseio.com")
                if myRootRef.authData.uid != nil {
                self.performSegueWithIdentifier("loginToGreet", sender: nil)

                  }

Error message beside the second to last line reads "Thread 1: EXC_BAD_INSTRUCTION and below reads "fatal error: unexpectedly found nil while unwrapping an Optional value(lldb)" 倒数第二行旁边的错误消息显示为“线程1:EXC_BAD_INSTRUCTION,下方显示为”致命错误:在展开可选值(lldb)时意外发现nil”

This was working when we initially put the project on the shelf. 当我们最初将项目放在架子上时,这种方法就起作用了。 The next chunk of code, if it matters: 下一段代码,如果有关系的话:

    @IBAction func loginPress(sender: UIButton) {
    let myRootRef = Firebase(url:"https://xxx.firebaseio.com")
    myRootRef.authUser(self.patientLoginName.text, password:self.patientLoginPassword.text,
        withCompletionBlock: { error, authData in
            if error != nil {
                // There was an error logging in to this account
                print(error)
            } else {
                // We are now logged in
                print(authData)
                self.performSegueWithIdentifier("loginToGreet", sender: nil)
            }
    })

Try 尝试

  if myRootRef.authData != nil {
     self.performSegueWithIdentifier("loginToGreet", sender: nil)
  }

authData might be nil and you are checking for authData.uid. authData可能为nil,并且您正在检查authData.uid。 Since authData is nil it will crash at the uid access so change your error checking like above. 由于authData为nil,它将在uid访问时崩溃,因此请像上面那样更改错误检查。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM