//setup service config
AWSServiceConfiguration *serviceConfiguration = [[AWSServiceConfiguration alloc] initWithRegion:CognitoIdentityUserPoolRegion credentialsProvider:nil];
//create a pool
AWSCognitoIdentityUserPoolConfiguration *configuration = [[AWSCognitoIdentityUserPoolConfiguration alloc] initWithClientId:CognitoIdentityUserPoolAppClientId clientSecret:nil poolId:CognitoIdentityUserPoolId];
[AWSCognitoIdentityUserPool registerCognitoIdentityUserPoolWithConfiguration:serviceConfiguration userPoolConfiguration:configuration forKey:@"UserPool"];
AWSCognitoIdentityUserPool *pool = [AWSCognitoIdentityUserPool CognitoIdentityUserPoolForKey:@"UserPool"];
pool.delegate = self;
AWSCognitoCredentialsProvider *credentialsProvider = [[AWSCognitoCredentialsProvider alloc] initWithRegionType:CognitoIdentityUserPoolRegion
identityPoolId:CognitoIdentityPoolId];
AWSServiceConfiguration *configuration1 = [[AWSServiceConfiguration alloc] initWithRegion:CognitoIdentityUserPoolRegion
credentialsProvider:credentialsProvider];
[AWSServiceManager defaultServiceManager].defaultServiceConfiguration = configuration1;
Above is my code in appdelegate. I'm using sample from AWS document "CognitoYourUserPool" to login. And trying to call API using Generated SDK for iOS.
API_Client *apiInstance = [API_Client defaultClient];
[apiInstance setAPIKey:@"xxxxxxxxxxxxxxxxxxxxxx"];
[[apiInstance presetTypeGet] continueWithBlock:^id _Nullable(AWSTask * _Nonnull t) {
NSLog(@"error: %@",t.error);
NSLog(@"result: %@",t.result);
return nil;
}];
I did call the API after logged in. but it's error. I dont know why for now. Please help me. If you need more information please ask. Thank you very much.
After 2 days, I figure it out.
AWSCognitoCredentialsProvider *credentialsProvider = [[AWSCognitoCredentialsProvider alloc] initWithRegionType:CognitoIdentityUserPoolRegion
identityPoolId:CognitoIdentityPoolId identityProviderManager:pool];
Need to set identityProviderManager. Thank you very much.