AWSCognito ユーザープールを使用してログインしようとしていますが、AWSCognitoIdentityInteractiveAuthenticationDelegate メソッドが呼び出されていません。これが私のコードです。どこが間違っていますか?
import UIKit
import AWSCognito
import AWSCognitoIdentityProvider
class LoginViewController: UIViewController, AWSCognitoIdentityInteractiveAuthenticationDelegate {
@IBOutlet weak var cancelButton: UIButton!
@IBOutlet weak var emailTextField: UITextField!
@IBOutlet weak var passwordTextField: UITextField!
var passwordAuthenticationCompletion: AWSTaskCompletionSource<AWSCognitoIdentityPasswordAuthenticationDetails>?
let pool = AWSCognitoIdentityUserPool(forKey: "UserPool")
var user: AWSCognitoIdentityUser?
override func viewDidLoad() {
super.viewDidLoad()
loginButton.layer.cornerRadius = 10
loginButton.layer.borderWidth = 1
pool.delegate = self
}
@IBAction func loginTap(_ sender: Any) {
if let email = emailTextField.text, let password = passwordTextField.text {
if email.isValidEmail() {
let authDetails = AWSCognitoIdentityPasswordAuthenticationDetails.init(username: email, password: password)
self.passwordAuthenticationCompletion?.set(result: authDetails)
self.user?.getSession()
} else {
let alert = UIAlertController(title: "Alert", message: "Invalid Email or password", preferredStyle: UIAlertController.Style.alert)
alert.addAction(UIAlertAction(title: "OK", style: UIAlertAction.Style.default, handler: nil))
self.present(alert, animated: true, completion: nil)
}
}
}
@IBAction func cancelButtonTap(_ sender: Any) {
dismiss(animated: true, completion: nil)
DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) {
NotificationCenter.default.post(name: NSNotification.Name("goToPaymentPageVC"), object: nil)
}
}
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
emailTextField.resignFirstResponder()
passwordTextField.resignFirstResponder()
}
//:- MARK: AWSCognitoIdentityInteractiveAuthenticationDelegate methods
func getDetails(_ authenticationInput: AWSCognitoIdentityPasswordAuthenticationInput, passwordAuthenticationCompletionSource: AWSTaskCompletionSource<AWSCognitoIdentityPasswordAuthenticationDetails>) {
self.passwordAuthenticationCompletion = passwordAuthenticationCompletionSource
DispatchQueue.main.async {
if (self.emailTextField.text == nil) {
self.emailTextField.text = authenticationInput.lastKnownUsername
}
}
}
func didCompleteStepWithError(_ error: Error?) {
DispatchQueue.main.async {
if let error = error as NSError? {
let alertController = UIAlertController(title: "Error",
message: error.userInfo["message"] as? String,
preferredStyle: .alert)
let retryAction = UIAlertAction(title: "Retry", style: .default, handler: nil)
alertController.addAction(retryAction)
self.present(alertController, animated: true, completion: nil)
} else {
self.emailTextField.text = nil
self.dismiss(animated: true, completion: nil)
DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) {
NotificationCenter.default.post(name: NSNotification.Name("goToPaymentPageVC"), object: nil)
}
}
}
}
}
期待される結果: AWSCognitoIdentityInteractiveAuthenticationDelegate メソッドを呼び出し、loginViewController を閉じる必要があります。