【发布时间】:2020-06-06 22:00:14
【问题描述】:
我尝试了几种不同的方法,但在这一点上我很难过。我只是希望能够访问用户的电子邮件以将其呈现在视图中。但是,我无法成功呈现,更不用说检索这些信息了。这是我尝试过的两段代码:
func getUsername() -> String? {
if(self.isAuth) {
return AWSMobileClient.default().username
} else {
return nil
}
}
和
func getUserEmail() -> String {
var returnValue = String()
AWSMobileClient.default().getUserAttributes { (attributes, error) in
if(error != nil){
print("ERROR: \(String(describing: error))")
}else{
if let attributesDict = attributes{
//print(attributesDict["email"])
self.name = attributesDict["name"]!
returnValue = attributesDict["name"]!
}
}
}
print("return value: \(returnValue)")
return returnValue
}
有谁知道为什么这不起作用?
【问题讨论】:
-
成功登录后,我可以使用
AWSCognitoIdentityUserPool.default().currentUser()?.username获取 currentUser 用户名。但我无法获取其余属性.. 你成功了吗?
标签: swift amazon-web-services swiftui amazon-cognito aws-amplify