AWS Cognito error: Authentication delegate not set

AWS Cognito error: Authentication delegate not set

我正在 Swift 使用 XCode 7.3 开发一个 iOS 应用程序。该应用程序与 DynamoDB 数据库通信,允许用户读取和写入数据。最近,我更新了我的 pods,其中包括 AWSDynamoDBAWSCognitoAWSCognitoIdentityProvider 和其他 AWS pods。我还根据此页面上的说明设置了一个新的用户池:

http://docs.aws.amazon.com/cognito/latest/developerguide/amazon-cognito-integrating-user-pools-with-identity-pools.html

作为遵循这些说明的一部分,我将以下代码放入 AppDelegate class 的 didFinishLaunchingWithOptions 方法中:

let serviceConfiguration = AWSServiceConfiguration(region: .USEast1, credentialsProvider: nil)
    let userPoolConfiguration = AWSCognitoIdentityUserPoolConfiguration(clientId:APP_CLIENT_ID, clientSecret: appSecret, poolId: USER_POOL_ID)
    AWSCognitoIdentityUserPool.registerCognitoIdentityUserPoolWithConfiguration(serviceConfiguration, userPoolConfiguration: userPoolConfiguration, forKey: USER_POOL_NAME)
    let pool = AWSCognitoIdentityUserPool(forKey:USER_POOL_NAME)
    let credentialsProvider = AWSCognitoCredentialsProvider(regionType: .USEast1, identityPoolId: IDENTITY_POOL_ID, identityProviderManager:pool)
    let configuration = AWSServiceConfiguration(region:.USEast1, credentialsProvider:credentialsProvider)
    AWSServiceManager.defaultServiceManager().defaultServiceConfiguration = configuration

我通过从 AWS 控制台导航到 Cognito、Federated Identities、我按照说明 "Edit Identity Pool" 创建的身份池获得了 IDENTITY_POOL_ID 的值,然后复制显示的字符串在 "identity pool ID" 旁边。我通过在同一页面上展开 "Authentication Providers" 并选择 "Cognito" 选项卡来获得 APP_CLIENT_ID 的值。对于 USER_POOL_NAME,我使用了此页面上的 "identity pool name",对于 USER_POOL_ID,我使用了 "Authentication Providers" 下列出的 "user pool ID" 值。我不清楚我是否正确设置了这些值,因为我不完全确定开发人员指南说我应该使用哪些值。

更新 pods 并进行这些更改后,当我 运行 应用程序时,我看到错误:

[Error] AWSCredentialsProvider.m line:569 | __44-[AWSCognitoCredentialsProvider credentials]_block_invoke.345 | Unable to refresh. Error is [Error Domain=com.amazonaws.AWSCognitoIdentityProviderErrorDomain Code=-1000 "Authentication delegate not set" UserInfo={NSLocalizedDescription=Authentication delegate not set}]

现在也无法访问 DynamoDB 数据,但该应用程序仍会启动。我怀疑部分问题是我的 DynamoDB 数据库不在 USEast 中,但我不确定这是否真的会导致此错误。除了更改 AppDelegate 中的代码外,我还尝试查找导致此错误的可能原因,但错误仍然存​​在。我可以调查哪些可能的原因?如果它有所作为,除了恢复 DynamoDB 功能外,我还尝试允许应用程序授权用户,我希望在解决此问题的过程中完成这两项工作。

您在尝试让用户注册或登录时似乎遇到了这个问题。在您的示例代码中,您没有设置 pool.delegate 值。这一行应该在你的 AppDelegate

pool.delegate = self

这也应该实施 AWSCognitoIdentityInteractiveAuthenticationDelegate

此博客 post 应该可以帮助您入门: https://mobile.awsblog.com/post/TxGNH1AUKDRZDH/Announcing-Your-User-Pools-in-Amazon-Cognito

示例应用程序也可能有帮助 https://github.com/awslabs/aws-sdk-ios-samples/blob/75ada5b6283b7c04c1214b2e1e0a6394377e3f2b/CognitoYourUserPools-Sample/Objective-C/CognitoYourUserPoolsSample/AppDelegate.h