作为iOS Swift开发的新手,我想知道是否有人可以帮助我了解针对身份验证错误(例如,错误的用户名和密码)自定义客户端警报消息的正确方法。下面是默认警报消息,该消息以异常名称作为标题,这不是良好的用户体验。如何显示带有其他标题和消息的警报弹出窗口?
答案 0 :(得分:0)
我认为您正在寻找UIAlertController。
快速示例:
let alert = UIAlertController(title: "Hello!", message: "Message", preferredStyle: UIAlertController.Style.alert)
let alertAction = UIAlertAction(title: "OK!", style: UIAlertAction.Style.default)
{
(UIAlertAction) -> Void in
}
alert.addAction(alertAction)
present(alert, animated: true)
{
() -> Void in
}
希望有帮助!
答案 1 :(得分:0)
处理您的错误响应以定义自定义标题和消息,例如 下面。
import AWSCognitoIdentityProvider
extension Error {
var customizedDescription: String {
let nsError = self as NSError
if nsError.domain == AWSCognitoIdentityProviderErrorDomain, let code = AWSCognitoIdentityProviderErrorType(rawValue: nsError.code) {
switch code {
case .expiredCode: return "Verification code has expired. Please try again"
case .codeMismatch: return "Incorrect verification code. Please enter the correct code to continue."
case .notAuthorized: return "Authentication failed. Please enter the correct credentials to continue."
case .usernameExists: return "Username already exists."
case .invalidPassword: return "Invalid password. Please try again."
case .userNotConfirmed: return "User not confirmed. Please verify your account."
default: return nsError.userInfo["message"] as? String ?? "AWS cognito failed with error code: \(nsError.code)"
}
}
return localizedDescription
}
}
https://gist.github.com/Catherine-K-George/11a94271bd0cff282e019cd2613d089b