[英]How to get an error message out of an NSError of Firebase auth login
当我尝试打印firebase用户登录的可读,userfrendly错误消息时,我发现我无法使用NSError.localizedDiscreption
casue它将显示“查找详细信息”。
当我使用print(error)
命令时,我的错误消息如下所示
2016-05-23 21:29:33.035 Mission Board[3251:] <FIRAnalytics/INFO> Firebase Analytics enabled
Optional(Error Domain=FIRAuthErrorDomain Code=17999 "An internal error has occurred, print and inspect the error details for more information." UserInfo={NSUnderlyingError=0x1277e2bb0 {Error Domain=FIRAuthInternalErrorDomain Code=3 "(null)" UserInfo={FIRAuthErrorUserInfoDeserializedResponseKey=<CFBasicHash 0x1288eec60 [0x1a172a150]>{type = immutable dict, count = 3,
entries =>
0 : <CFString 0x12890ad60 [0x1a172a150]>{contents = "message"} = <CFString 0x1288eec20 [0x1a172a150]>{contents = "INVALID_EMAIL"}
1 : errors = <CFArray 0x12890ad20 [0x1a172a150]>{type = immutable, count = 1, values = (
0 : <CFBasicHash 0x12890c660 [0x1a172a150]>{type = immutable dict, count = 3,
entries =>
0 : reason = invalid
1 : message = <CFString 0x128872790 [0x1a172a150]>{contents = "INVALID_EMAIL"}
2 : domain = global
}
)}
2 : code = <CFNumber 0xb000000000001903 [0x1a172a150]>{value = +400, type = kCFNumberSInt64Type}
}
}}, error_name=ERROR_INTERNAL_ERROR, NSLocalizedDescription=An internal error has occurred, print and inspect the error details for more information.})
这不是很可读但我在条目1代码0中找到,有一条内容为“INVALID EMAIL”的消息
我可以将该部分输出到用户的警报吗?
是否有内置功能可以做到这一点?
下面的代码是我的注册错误控制。 我使用KVNProgress pod进行提醒。
Swift3
import KVNProgress
FIRAuth.auth()?.createUser(withEmail: self.emailTextLbl.text!, password: self.passwordTextLbl.text!, completion: { (user, error) in
if error != nil {
let error2:NSError = error as! NSError
if error2.code == FIRAuthErrorCode.errorCodeInvalidEmail.rawValue {
KVNProgress.showError(withStatus: "Invalid Email", completion: nil)
}else if error2.code == FIRAuthErrorCode.errorCodeNetworkError.rawValue {
KVNProgress.showError(withStatus: "Network Error", completion: nil)
}else if error2.code == FIRAuthErrorCode.errorCodeWeakPassword.rawValue {
KVNProgress.showError(withStatus: "Weak Password", completion: nil)
}else if error2.code == FIRAuthErrorCode.errorCodeEmailAlreadyInUse.rawValue {
KVNProgress.showError(withStatus: "Email Already In Use", completion: nil)
}
}else{
// Your code
}
})
您可以在“FIRAuthErrorCode”中找到其他错误控件,例如登录错误处理。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.