我在通过 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)
}
})
}
附言当我尝试注册时一切正常。用户已创建,但 popUpViewController
在这里不起作用。
附言我已经看到类似的问题"An error occurred while accessing the keychain" when signing in using Firebase ,但对此一无所知。另请阅读此 https://firebase.google.com/docs/auth/ios/errors .
最佳答案
解决此问题的步骤: 转到项目目标 -> 功能 -> 打开“钥匙串(keychain)共享”
关于ios - FIRAuth : An error has occurred while accessing the keychain (Swift 3),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39555289/