更新:
我正在尝试将用户添加到我的身份池。我不断收到此错误消息:
Error: The operation couldn’t be completed. (com.amazonaws.AWSCognitoIdentityErrorDomain error 8.)
Error Domain=com.amazonaws.AWSCognitoIdentityErrorDomain Code=8 "(null)" UserInfo={__type=NotAuthorizedException, message=Unauthenticated access is not supported for this identity pool.}
此代码在启动时位于我的App Delegate
中
//sets up dynamo db
let credentialProvider = AWSCognitoCredentialsProvider(regionType: .USEast1, identityPoolId: CognitoIdentityPoolId)
let configuration = AWSServiceConfiguration(region: .USEast1, credentialsProvider: credentialProvider)
AWSServiceManager.default().defaultServiceConfiguration = configuration
然后在我的主要ViewController
中:
let credentialsProvider = AWSCognitoCredentialsProvider(regionType: .USEast1, identityPoolId: CognitoIdentityPoolId)
let configuration = AWSServiceConfiguration(region: .USEast1, credentialsProvider: credentialsProvider)
AWSServiceManager.default().defaultServiceConfiguration = configuration
credentialsProvider.getIdentityId().continueWith(block: { (task) -> AnyObject? in
if (task.error != nil){
print("Error: " + task.error!.localizedDescription)
print(task.error!)
}
else {
// the task result will contain the identity id
let cognitoId = task.result!
print("Cognito id: \(cognitoId)")
}
return task;
})
我知道在运行该代码时,用户已经成功登录。可以在此page上找到类似的代码。
更新2:
在我的AppDelegate
中,似乎有重复的代码将AWSServiceManager.default().defaultServiceConfiguration
设置为两次,根据this的消息,第二次被忽略了
这可能就是为什么我得到一个空错误。当再次调用该代码时,凭据提供者为null(也许)。因此,如果我在AppDelegate
中注释掉这三行,则会收到一个新错误:
Optional(Error Domain=com.amazonaws.service.cognitoidentity.AWSCognitoCredentialsProviderHelper Code=0 "Obtaining an identity id in another thread failed or didn't complete within 5 seconds."
UserInfo={NSLocalizedDescription=Obtaining an identity id in another thread failed or didn't complete within 5 seconds.})
我不确定我还可以在哪里拨打ID。特别是如果我从AppDelegate
删除了代码,我们将不胜感激!
有关身份池的一些信息:
我不希望任何未经身份验证的访问权限,因此在控制台中进行设置时,这些是我选择的设置。并且我已进行了三次检查,以确保所有AppId
,AppSecrets
等均已正确复制。