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

时间:2017-01-24 14:00:26

标签: swift amazon-web-services amazon-cognito aws-cognito

我终于设法使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告诉我。但是,如果我在空间中输入任何内容,则没有任何反应。打印声明"至少这是有效的......"永远不会被召唤。我现在一直在盯着这段代码几个小时试图找出错误,我觉得它可能很简单,但截至目前,我可以使用一些帮助!

提前致谢!

1 个答案:

答案 0 :(得分:1)

我认为上面的代码块不是完整的源代码,但请确保可选user为“未封装”且等于AWSCognitoIdentityUser的实际实例

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

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

我相信您在对AWSCognitoIdentityUserPool课程signUp:password:userAttributes:validationData:电话的回复中将其设置为与该实例类型相同。

检查AWSCognitoIdentityUserPoolSignUpResponse中返回的值。