方案:
gmail.com
电子邮件帐户,但未对其进行确认。问题 我应该抓到什么错误告诉用户电子邮件已经是另一种身份验证方法的用户?
代码
func signIn(with email: String, and password: String) {
let credential = EmailAuthProvider.credential(withEmail: email, password: password)
Auth.auth().signIn(with: credential) { (user, error) in
if let error = error {
print(error.localizedDescription)
self.delegate.hideActivityIndicatorView()
if let errorCode = AuthErrorCode(rawValue: error._code) {
switch errorCode {
case .accountExistsWithDifferentCredential, .credentialAlreadyInUse:
self.delegate.presentAlert(title: "An account with this email already exists", message: nil)
case .userNotFound, .wrongPassword, .invalidEmail:
self.delegate.presentAlert(title: "Unable to Sign In", message: "Either email or password is incorrect.")
default:
self.delegate.presentAlert(title: "Something went wrong, please try again later.", message: nil)
return
}
}
}
print("Successful Email Sign In.")
self.delegate.hideActivityIndicatorView()
}
}