我正在使用 SDK Amplify 构建一个 iOS 应用程序,以便我的用户在 AWS 上注册。
我的登录/注册流程已经可以运行,但问题是,使用最新版本的 SDK,我完全不知道如何获取注册用户的属性,例如他的姓氏、电子邮件地址等...
使用这个新的 SDK,一切似乎都围绕
AWSMobileClient
类进行,但我从这个类中看不到任何可以帮助我获得我想要的东西。
官方文档缺乏内容,没有涵盖甚至没有指出我的用例。
如果有人能给我一些提示,甚至一些好的资源,我将非常感激!
嗨 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
,它来自于此处找到的集成测试。
该方法在初始版本中缺失,现已添加。您可以在最新的 SDK 版本中通过以下 API 使用 getUserAttributes
2.8.x
:
public func getUserAttributes(completionHandler: @escaping (([String: String]?, Error?) -> Void))
您可以在这里找到源代码: