ios - 是否可以使用 iOS SDK 在 Amazon Cognito 中更改用户名?

标签 ios amazon-cognito

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

最佳答案

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

The username value is a separate attribute and not the same as the name attribute. A username is always required to register a user, and it cannot be changed after a user is created.

但是,preferred_username 值确实可以更改,并且根据官方 documentation 提供了使用 iOS SDK 更改首选用户名的示例代码表述如下:

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有疑问时。

关于ios - 是否可以使用 iOS SDK 在 Amazon Cognito 中更改用户名?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55774309/

相关文章:

ios - iOS 12.4 上的 Chrome 和 Safari 没有及时设置 cookie

iphone - 将 UIVIewController 推送到 UIView

javascript - 如何解决 AWS Cognito 开发工具包错误 : "Client <XYZ> is configured for secret but secret was not received?"

java - 如何从用 JAVA 编写的 AWS Lambda 中的 Cognito Identity 获取临时凭证

ios - 标签栏 : interaction between tabs

iOS - 使用 Swift 的 CAEmitterCell

ios - 当表格 View 滚动 Swift 时,文本字段变为空

amazon-web-services - 如何更改用户状态FORCE_CHANGE_PASSWORD?

amazon-web-services - Cognito 用户池 - 确认后触发、访问被拒绝异常

amazon-web-services - 在 Cognito 内置登录页面中显示用户名以外的内容