2016-09-18 61 views
0

我遇到了通过Firebase登录的问题。当它是Swift 2时,一切都很顺利,但是在XCode将我的整个项目转换为Swift 3语法后,出现了错误。FIRAuth:访问钥匙串时发生错误(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) 
       } 
      }) 
     } 

附:当我尝试注册时,一切正常。用户已创建,但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

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