FIRAuth:访问钥匙串时发生错误(Swift 3)

时间:2016-09-18 07:46:25

标签: ios firebase firebase-authentication swift3

我遇到了通过Firebase登录的问题。当它是Swift 2时,一切都没问题,但是在XCode将我的整个项目转换为Swift 3语法之后,发生了错误。

这是我的登录代码:

func loginDidFinish(_ email: String, password: String, type: LoginViewController.SendType) {

        // Server call implementation here
        if type == .login {
            FIRAuth.auth()?.signIn(withEmail: email, password: password, completion: { (user, error) in

                if error != nil {
                    self.alert = UIAlertController(title: "Error", message: error?.localizedDescription, preferredStyle: .alert)
                    self.present(self.alert, animated: true, completion: nil)
                    let delay = Double(2) * Double(NSEC_PER_SEC)
                    let time = DispatchTime.now() + Double(Int64(delay)) / Double(NSEC_PER_SEC)
                    DispatchQueue.main.asyncAfter(deadline: time) { [weak self] in
                        self!.alert.dismiss(animated: true, completion: nil)
                    }
                } else {

                    _ = self.navigationController?.popViewController(animated: true)
                }
            })
        } else { // type == .SignUp
            FIRAuth.auth()?.createUser(withEmail: email, password: password, completion: { (user, error) in

                if error != nil {
                    self.alert = UIAlertController(title: "Error", message: error?.localizedDescription, preferredStyle: .alert)
                    self.present(self.alert, animated: true, completion: nil)
                    let delay = Double(2) * Double(NSEC_PER_SEC)
                    let time = DispatchTime.now() + Double(Int64(delay)) / Double(NSEC_PER_SEC)
                    DispatchQueue.main.asyncAfter(deadline: time) { [weak self] in
                        self!.alert.dismiss(animated: true, completion: nil)
                    }
                } else {

                    _ = self.navigationController?.popViewController(animated: true)
                }
            })
        }

P.S。我尝试注册时一切正常。用户已创建,但popUpViewController在此处无效。

P.P.S。我已经看到了类似的问题"An error occurred while accessing the keychain" when signing in using Firebase,但是对此一无所知。另请阅读此https://firebase.google.com/docs/auth/ios/errors

1 个答案:

答案 0 :(得分:1)

解决此问题的步骤: 转到项目目标 - >能力 - >打开“钥匙串共享”