0

我终于设法让 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
    })

}

此代码的第一部分工作正常。如果我在空格中不输入任何内容,我会收到一个 alertView 告诉我。但是,如果我在空格中键入任何内容,则不会发生任何事情。打印语句“至少这是有效的......”永远不会被调用。我已经盯着这段代码看了几个小时,试图找出问题所在,我觉得这可能很简单,但到目前为止,我可以使用一些帮助!

提前致谢!

4

1 回答 1

1

我假设上面的代码块不是完整的源代码,但请确保可选user, 是“未封装的”并且等于AWSCognitoIdentityUser.

如果不是,我假设它不是,confirmSignUp将不知道username, sub,或者有关于它正在“确认”的用户的任何信息。

我建议记录user并确保它username实际上是user.

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

检查那些返回的值AWSCognitoIdentityUserPoolSignUpResponse

于 2017-01-24T14:41:31.383 回答