Reputation: 343
I am developing an iOS app in Swift using XCode 7.3. The app communicates with a DynamoDB database, allowing the user to read and write data. Recently, I updated my pods, which include AWSDynamoDB
, AWSCognito
, AWSCognitoIdentityProvider
, and other AWS pods. I also set up a new user pool according to the instructions on this page:
As part of following these instructions, I put the following code in the AppDelegate class's didFinishLaunchingWithOptions method:
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
I got the value for IDENTITY_POOL_ID
by navigating starting from the AWS console to Cognito, Federated Identities, the identity pool I created while following the instructions, "Edit Identity Pool", and then copying the string shown next to "identity pool ID". I obtained the value for APP_CLIENT_ID
by expanding "Authentication Providers" on the same page and selecting the "Cognito" tab. For USER_POOL_NAME
, I used the "identity pool name" on this page, and for USER_POOL_ID
I used the "user pool ID" value listed under "Authentication Providers". I am unclear as to whether I set these values correctly, since I wasn't entirely sure which values the developer guide was saying I should use.
After updating the pods and making these changes, when I run the app, I see the error:
[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}]
It is also now impossible to access the DynamoDB data, though the app does still launch. I suspect part of the problem is that my DynamoDB database is not in USEast, but I'm unsure whether this would actually result in this error. I have tried to look up possible causes for this error in addition to changing the code in AppDelegate, but the error remains the same. What are some likely causes I can investigate? If it makes a difference, I am trying to allow the app to authorize the user in addition to restoring the DynamoDB functionality, and I would like to accomplish both in the process of fixing this issue.
Upvotes: 5
Views: 6229
Reputation: 993
It looks like the issue you are having comes up when trying to have a user sign up or log in. In your sample code you do not set the pool.delegate value. This line should be in your AppDelegate
pool.delegate = self
This should also implement AWSCognitoIdentityInteractiveAuthenticationDelegate
This Blog post should assist you in getting started: https://mobile.awsblog.com/post/TxGNH1AUKDRZDH/Announcing-Your-User-Pools-in-Amazon-Cognito
The sample application might also be helpful https://github.com/awslabs/aws-sdk-ios-samples/blob/75ada5b6283b7c04c1214b2e1e0a6394377e3f2b/CognitoYourUserPools-Sample/Objective-C/CognitoYourUserPoolsSample/AppDelegate.h
Upvotes: 5