【发布时间】:2017-08-12 11:08:55
【问题描述】:
我正在使用带有 Amazon's Swift sample app 的 AWS Cognito 用户池。我可以创建具有given_name 属性的用户,但以后如何检索given_name 并不明显。
Amazon 示例将属性检索为AWSCognitoIdentityUserGetDetailsResponse,然后将它们转储到屏幕上。但是,我找不到AWSCognitoIdentityUserGetDetailsResponse 的文档。它似乎是一个数组,但对我来说如何从返回的属性中提取 given_name 并不明显。有人会认为将属性作为字典返回是个好主意,但亚马逊似乎并没有那样做。
任何指针?
编辑:澄清一下,返回的是AttributeType 对象的数组。下面是 Cognito 示例中的代码,它显示了所有返回的属性:
override func tableView(_ tableView: UITableView, cellForRowAt
indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "attribute", for: indexPath)
let userAttribute = self.response?.userAttributes![indexPath.row]
cell.textLabel!.text = userAttribute?.name
cell.detailTextLabel!.text = userAttribute?.value
return cell
}
这是原始响应:
Response body:
{"UserAttributes":[{"Name":"sub","Value":"XXXXXXXX-XXXX-XXXX-XXXX-
XXXXXXXXXXXX"},{"Name":"email_verified","Value":"true"},
{"Name":"given_name","Value":"Bob"},
{"Name":"email","Value":"bob@example.com"}],"Username":"AAAAAAA-BBBB-CCCC-DDDD-EEEEEEEEEEEE"}
在不遍历整个数组的情况下如何提取given_name 对我来说并不明显。
【问题讨论】:
标签: swift amazon-web-services swift3 amazon-cognito