获取用户属性 AWS Amplify iOS SDK

问题描述 投票:0回答:3

我正在使用 SDK Amplify 构建一个 iOS 应用程序,以便我的用户在 AWS 上注册。

我的登录/注册流程已经可以运行,但问题是,使用最新版本的 SDK,我完全不知道如何获取注册用户的属性,例如他的姓氏、电子邮件地址等...

使用这个新的 SDK,一切似乎都围绕

AWSMobileClient
类进行,但我从这个类中看不到任何可以帮助我获得我想要的东西。

官方文档缺乏内容,没有涵盖甚至没有指出我的用例。

如果有人能给我一些提示,甚至一些好的资源,我将非常感激!

ios swift amazon-web-services amazon-cognito aws-amplify
3个回答
3
投票

嗨 YoanGJ 和未来的客人,

根据您的评论,您正在寻找一些示例代码。

    AWSMobileClient.sharedInstance().getUserAttributes { (attributes, error) in
            if let attributes = attributes {
                XCTAssertTrue(attributes.count == 3, "Expected 3 attributes for user.")
                XCTAssertTrue(attributes["email_verified"] == "false", "Email should not be verified.")
            }else if let error = error {
                XCTFail("Received un-expected error: \(error.localizedDescription)")
            }
            getAttrExpectation.fulfill()
}

此摘录显示了如何调用

getUserAttributes
,它来自于此处找到的集成测试。


2
投票

该方法在初始版本中缺失,现已添加。您可以在最新的 SDK 版本中通过以下 API 使用 getUserAttributes

2.8.x
:

public func getUserAttributes(completionHandler: @escaping (([String: String]?, Error?) -> Void))

您可以在这里找到源代码:

https://github.com/aws-amplify/aws-sdk-ios/blob/master/AWSAuthSDK/Sources/AWSMobileClient/AWSMobileClientExtensions.swift#L532


0
投票

备注:

确保您在 Cognito 用户池应用程序客户端中相应配置了属性读写权限,以使用

getUserAttributes
访问您的用户属性。

配置用户池属性读写权限,

用户池 -> 常规设置 -> 应用程序客户端 -> 选择您的应用程序客户端 -> 显示详细信息 -> 设置属性读写权限

enter image description here

谢谢!

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.