使用 Xcode 在 Swift 中确认用户身份时,AWS Cognito 不会调用 confirmSignUp

AWS Cognito doesn't call confirmSignUp when confirming user identity in Swift with Xcode

我终于设法让 SignUp 正常工作,但是在尝试确认注册时遇到了问题。这是我的代码:

var user: AWSCognitoIdentityUser?

@IBAction func submitButton(_ sender: Any) {
    guard let confirmationCodeValue = self.codeTextField.text, !confirmationCodeValue.isEmpty else {
        let confirmationAlert = UIAlertController(title: alertTitle, message: alertMessage, preferredStyle: .alert)
        confirmationAlert.addAction(UIAlertAction(title: "好", style: .default, handler: {action in
            print("Try again!")
        }))
        self.present(confirmationAlert, animated: true, completion: nil)

        return
    }

    self.user?.confirmSignUp(self.codeTextField.text!, forceAliasCreation: true).continue({[weak self] (task: AWSTask) -> Any? in
        guard let strongSelf = self else { return nil }
        DispatchQueue.main.async(execute: {
            print("At least this is working...")
            if let error = task.error {
                let confirmationFailAlert = UIAlertController(title: (error as NSError).userInfo["__type"] as? String,
                                                              message: (error as NSError).userInfo["__type"] as? String,
                                                              preferredStyle: .alert)
                confirmationFailAlert.addAction(UIAlertAction(title: "好",
                                                              style: .default,
                                                              handler: {action in
                }))
                self?.present(confirmationFailAlert, animated: true, completion: nil)
            } else {
                let confirmationSuccessAlert = UIAlertController(title: self?.alertTitleConfirmationComplete,
                                                                 message:self?.alertMessageConfirmationComplete,
                                                                 preferredStyle: .alert)
                confirmationSuccessAlert.addAction(UIAlertAction(title: "好",
                                                                 style: .default,
                                                                 handler: {action in
                                                                    self?.dismiss(animated: true, completion: nil)
                }))
                self?.present(confirmationSuccessAlert, animated: true, completion: nil)
            }
        })
        return nil
    })

}

这段代码的第一部分工作正常。如果我在 space 中什么都不输入,我会收到一个 alertView 告诉我。但是,如果我在 space 中键入任何内容,则什么也不会发生。打印语句 "At least this is working..." 永远不会被调用。我已经盯着这段代码看了几个小时,试图找出问题所在,我觉得这可能很简单,但到目前为止,我需要一些帮助!

提前致谢!

我假设上面的代码块不是完整的源代码,但请确保 可选的user 是 "unencapsulated" 并且等于实际的AWSCognitoIdentityUser.

的实例

如果不是,我假设它不是,confirmSignUp 将不知道 usernamesub,也不会知道它是哪个用户的任何信息"confirming".

我建议记录 user 并确保 username 实际上是 user 内的值。

我相信您在对 AWSCognitoIdentityUserPool class signUp:password:userAttributes:validationData: 调用的响应中将其设置为等于该实例类型。

检查 AWSCognitoIdentityUserPoolSignUpResponse 中返回的那些值。