在 Kotlin 中未调用 Cognito signUpInBackground 回调

Cognito signUpInBackground callback not called in Kotlin

我正在使用 Cognito 在 Kotlin 中为 Android 移动应用程序构建注册表单,但是当我尝试实际注册用户时遇到问题。

在文档中,我们可以看到这个示例 Java 注册用户的代码:

SignUpHandler signupCallback = new SignUpHandler() {

    @Override
    public void onSuccess(CognitoUser cognitoUser, boolean userConfirmed, CognitoUserCodeDeliveryDetails cognitoUserCodeDeliveryDetails) {
        // Sign-up was successful

        // Check if this user (cognitoUser) needs to be confirmed
        if(!userConfirmed) {
            // This user must be confirmed and a confirmation code was sent to the user
            // cognitoUserCodeDeliveryDetails will indicate where the confirmation code was sent
            // Get the confirmation code from user
        }
        else {
            // The user has already been confirmed
        }
    }

    @Override
    public void onFailure(Exception exception) {
        // Sign-up failed, check exception for the cause
    }
};

userPool.signUpInBackground(userId, password, userAttributes, null, signupCallback);

这是我在 Kotlin 中的版本:

var signupCallback: SignUpHandler = object : SignUpHandler {

    override fun onSuccess(cognitoUser: CognitoUser, userConfirmed: Boolean, cognitoUserCodeDeliveryDetails: CognitoUserCodeDeliveryDetails) {
        // Sign-up was successful

        // Check if this user (cognitoUser) needs to be confirmed
        if (!userConfirmed) {
            val intent = Intent(this@RegisterUsernameActivity, ConfirmEmailActivity::class.java)
            startActivity(intent)
            // This user must be confirmed and a confirmation code was sent to the user
            // cognitoUserCodeDeliveryDetails will indicate where the confirmation code was sent
            // Get the confirmation code from user
        } else {
            // The user has already been confirmed
        }
    }

    override fun onFailure(exception: Exception) {
        // Sign-up failed, check exception for the cause
        Log.d("ERROR", exception.localizedMessage.toString())
    }
}

userPool.signUpInBackground(username, password, userAttributes, null, signupCallback)

当我在成功和失败案例中放置日志时,没有任何打印,回调就像完全被忽略一样。你知道为什么吗?

编辑: 刚刚尝试了 Java 版本,正如记录的那样,同样的问题发生了。

刚刚重新启动了我的电脑,它工作了...