【问题标题】:Cognito signUpInBackground callback not called in Kotlin在 Kotlin 中未调用 Cognito signUpInBackground 回调
【发布时间】:2019-05-01 09:02:49
【问题描述】:

我正在使用 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 版本,正如它所记录的那样,同样的问题发生了。

【问题讨论】:

    标签: android amazon-web-services kotlin aws-sdk amazon-cognito


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-03-05
      • 2018-05-10
      • 2014-05-20
      • 2017-06-14
      • 2021-10-28
      • 2018-05-01
      相关资源
      最近更新 更多