As someone new to iOS Swift development, I was wondering if someone could help me understand the proper way to customize client-side alert messages for authentication errors such as incorrect username and password. Below is the default alert message, which has the exception name as the title, which is not good user experience. How would I go about displaying an alert popup with another title and message?
Asked
Active
Viewed 270 times
0
-
After you get response from server you can show any alert depend on your server response – canister_exister Jan 17 '19 at 21:29
-
You can create `ErrorHandler` and throw the error for your server response or using `switch` change your alert view message – canister_exister Jan 17 '19 at 21:31
-
I'm sorry, but your comment is too vague and probably doesn't even answer the actual question – btrballin Jan 17 '19 at 23:55
-
https://stackoverflow.com/questions/4988564/how-to-implement-a-pop-up-dialog-box-in-ios Is this what you are looking for? – Roshan Jan 18 '19 at 00:00
-
Not quite. I am looking for a way to customize the AWS drop-in UI for authentication – btrballin Jan 18 '19 at 00:18
-
1Customization of the alert window is not supported by the AWS drop-in UI. It provides limited customization options that are specified in the [documentation](https://aws-amplify.github.io/docs/ios/authentication#customization). For further customization you would have to fork the code and do the required customization yourself. – Roshan Jan 18 '19 at 18:34
-
Yup. That's what I discovered as well. I went ahead and modified the part of the code where the alert is triggered myself and it looks like their GitHub repo has an issue filed under the issue tracker here: https://github.com/aws-amplify/aws-sdk-ios/issues/1156. You would think an enterprise product by AWS wouldn't overlook such crucial aspects like this that affect the user experience of production-ready apps. – btrballin Jan 19 '19 at 00:24
2 Answers
0
I think you are looking for UIAlertController.
Swift sample :
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
}
Hope it helps!

Roshan
- 753
- 5
- 14
0
Handle your error response to define custom title & message like below.
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

Catherine
- 199
- 6