【问题标题】:Is it possible change username in Amazon Cognito with iOS SDK?是否可以使用 iOS SDK 更改 Amazon Cognito 中的用户名?
【发布时间】:2019-09-10 11:03:04
【问题描述】:

如标题中所述,是否可以更改 Amazon Cognito 用户的用户名?我在文档中找不到任何内容

【问题讨论】:

    标签: ios amazon-cognito


    【解决方案1】:

    可以使用 iOS SDK 使用 updateAttributes API 调用更新 Cognito 用户的 preferred_username。但是,请注意您将无法修改用户的username。引用官方 AWS 文档,

    用户名值是一个单独的属性,与 名称属性。注册用户始终需要用户名,并且 创建用户后无法更改。

    但是,preferred_username 的值确实可以更改,使用 iOS SDK 更改首选用户名的示例代码,按照官方的documentation 说明如下:

    AWSCognitoIdentityUserAttributeType * attribute = [AWSCognitoIdentityUserAttributeType new];
    attribute.name = @"preferred_username";
    attribute.value = @"John User";
    [[user updateAttributes:@[attribute]] continueWithSuccessBlock:^id _Nullable(AWSTask<AWSCognitoIdentityUserUpdateAttributesResponse *> * _Nonnull task) {
        //success
        return nil;
    }];
    

    我还想声明,iOS SDK 的 AWS API 文档非常少,我建议开发人员在有疑问时通过 SDK source code

    【讨论】:

    • 非常感谢Arka的回答!真的很感激!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-01-02
    • 2020-07-07
    • 2019-01-30
    • 2017-01-09
    • 1970-01-01
    • 2019-06-24
    • 2012-07-09
    相关资源
    最近更新 更多