В Cognito на iOS обработка требуемого нового пароля никогда не достигает didCompleteNewPasswordStepWithError

Я пытаюсь реализовать функцию ответа на FORCE_CHANGE_PASSWORD в моем приложении iOS, которое использует AWS Cognito. Я использовал этот вопрос о переполнении стека, который ссылается на этот пример кода. Прямо сейчас мой код открывает контроллер представления, как и положено; однако, оказавшись на этом контроллере представления, я не могу заставить его что-либо делать. В примере кода кажется, что когда вы хотите отправить запрос на смену пароля, вы вызываете.set на примере AWSTaskCompletionSource<AWSCognitoIdentityNewPasswordRequiredDetails>, но когда я это сделаю, функция протокола didCompleteNewPasswordStepWithErrorникогда не называется. Интересно, что другая функция протоколаgetNewPasswordDetails называется быстро после viewDidLoadи я не могу сказать почему. Я считаю, что это не следует вызывать, пока пользователь не введет свой новый пароль и т. Д., И должен быть в ответ на.set но я мог ошибаться.

Мой код почти идентичен образцу кода и тому сообщению SO, поэтому я не уверен, что здесь не так.

Мой соответствующий код AppDelegate находится здесь:

extension AppDelegate: AWSCognitoIdentityInteractiveAuthenticationDelegate {

    func startNewPasswordRequired() -> AWSCognitoIdentityNewPasswordRequired {

        //assume we are presenting from login vc cuz where else would we be presenting that from
        DispatchQueue.main.async {
            let presentVC = UIApplication.shared.keyWindow?.visibleViewController
            TransitionHelperFunctions.presentResetPasswordViewController(viewController: presentVC!)
            print(1)
        }

        var vcToReturn: ResetPasswordViewController?
        returnVC { (vc) in
            vcToReturn = vc
            print(2)
        }
        print(3)
        return vcToReturn!

    }

    //put this into its own func so we can call it on main thread
    func returnVC(completion: @escaping (ResetPasswordViewController) -> () ) {

        DispatchQueue.main.sync {
            let storyboard = UIStoryboard(name: "ResetPassword", bundle: nil)
            let resetVC = storyboard.instantiateViewController(withIdentifier: "ResetPasswordViewController") as? ResetPasswordViewController
            completion(resetVC!)
        }

    }
}

Мой соответствующий код ResetPasswordViewController находится здесь:


class ResetPasswordViewController: UIViewController, UITextFieldDelegate {

    @IBAction func resetButtonPressed(_ sender: Any) {

        var userAttributes: [String:String] = [:]
        userAttributes["given_name"] = firstNameField.text!
        userAttributes["family_name"] = lastNameField.text!

        let details = AWSCognitoIdentityNewPasswordRequiredDetails(proposedPassword: self.passwordTextField.text!, userAttributes: userAttributes)
        self.newPasswordCompletion?.set(result: details)

    }

}

extension ResetPasswordViewController: AWSCognitoIdentityNewPasswordRequired {

    func getNewPasswordDetails(_ newPasswordRequiredInput: AWSCognitoIdentityNewPasswordRequiredInput, newPasswordRequiredCompletionSource: AWSTaskCompletionSource<AWSCognitoIdentityNewPasswordRequiredDetails>) {

        self.newPasswordCompletion = newPasswordRequiredCompletionSource

    }

    func didCompleteNewPasswordStepWithError(_ error: Error?) {
        DispatchQueue.main.async {
            if let error = error as? NSError {
                print("error")
                print(error)
            } else {
                // Handle success, in my case simply dismiss the view controller
                SCLAlertViewHelperFunctions.displaySuccessAlertView(timeoutValue: 5.0, title: "Success", subTitle: "You can now login with your new passowrd", colorStyle: Constants.UIntColors.emeraldColor, colorTextButton: Constants.UIntColors.whiteColor)

                self.dismiss(animated: true, completion: nil)
            }
        }
    }

}

Большое спасибо за вашу помощь и дайте мне знать, если вам понадобится дополнительная информация.

0 ответов

Другие вопросы по тегам