ios - 使用 credentialsProvider 与 AWSMobileClient 检索 Cognito 身份 ID
问题描述
为什么我在使用凭证提供商的 getIdentityID 时成功获取 Cognito ID,但在使用 AWSMobileClient 时出现错误?
我已经使用自定义开发人员提供程序设置了联合身份。我正在使用 Amazon Cognito 控制台生成的代码段初始化 Amazon Cognito 凭证提供程序。
let credentialsProvider = AWSCognitoCredentialsProvider(regionType: .USEast1, identityPoolId: "IDENTITY_POOL_ID")
let configuration = AWSServiceConfiguration(region: .USEast1, credentialsProvider: credentialsProvider)
AWSServiceManager.default().defaultServiceConfiguration = configuration
在此之后,我正在使用以下内容检索 cognito Identity ID:
credentialsProvider.getIdentityId().continueWith(block: { (task) -> AnyObject? in
if (task.error != nil) {
print("Error: " + task.error!.localizedDescription)
}
else {
// the task result will contain the identity id
let cognitoId = task.result!
print("Cognito id: \(cognitoId)")
}
return task;
})
当我运行它时,我成功地检索了身份 ID,并且我还可以在我的控制台上将其视为联合身份的未经身份验证的用户。但是,当我尝试使用 AWSMobileClient 检索身份 ID 时,如下所示:
AWSMobileClient.sharedInstance().initialize { (userState, error) in
if let userState = userState {
print("UserState (AccountView): \(userState.rawValue)")
} else if let error = error {
print("error: \(error.localizedDescription)")
}
}
// Retrieve your Amazon Cognito ID
AWSMobileClient.sharedInstance().getIdentityId().continueWith { task in
if let error = task.error {
print("error: \(error.localizedDescription) \((error as NSError).userInfo)")
print(error)
}
if let result = task.result {
print("identity id: \(result)")
}
return nil
}
我收到 AWSMobileClient 错误 30:错误:cognitoIdentityPoolNotConfigured(消息:“无法获取 identityId,因为 cognito 凭证配置不可用。”)
为什么是这样?我错过了什么?
我正在使用AWSMobileClient、AWSCore
环境(请填写以下信息): - SDK 版本:'AWSMobileClient'、'~> 2.10.0'、'AWSCore'、'~> 2.10.0' - 依赖管理器:Cocoapods - Swift 版本:5.0 - Xcode 版本: 10.3
设备信息(请填写以下信息): - 设备:MacOS 10.14.5 - iOS 12.4
解决方案
推荐阅读
- php - 使用 REST API 将 WHMCS 与我的网站连接
- c# - 按钮单击在 ASP.NET 中的面板帖子中不起作用
- android - 飞机wifi恢复后世博会崩溃
- amazon-web-services - AWS SES 不发送电子邮件,尽管遵循指南 - Windows 操作系统
- php - 如果输入被禁用,表单输入不验证
- python-3.x - Python 3 导入:约定与性能?
- postgresql - Rails - PG:InvalidSchemaName
- c++ - 为什么 std::pair 不可构造?
- hyperlink - 如何从 ArcGIS shapefile 在 netlogo 中创建链接
- artifactory - 我如何对 JFrog Artifactory 的密码进行 base64 编码?