0
//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;

以上是我在 appdelegate 中的代码。我正在使用 AWS 文档“CognitoYourUserPool”中的示例登录。并尝试使用 Generated SDK for iOS 调用 API。

 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;
    }];

登录后我确实调用了 API。但这是错误的。我现在不知道为什么。请帮我。如果您需要更多信息,请询问。非常感谢你。

4

2 回答 2

0

试试这个:

AWSCognitoIdentityUserPoolConfiguration *configuration = [[AWSCognitoIdentityUserPoolConfiguration alloc] initWithClientId:CognitoIdentityUserPoolAppClientId  clientSecret:nil poolId:CognitoIdentityUserPoolId];

AWSCognitoCredentialsProvider *credentialsProvider = [[AWSCognitoCredentialsProvider alloc] initWithRegionType:CognitoIdentityUserPoolRegion identityPoolId:CognitoIdentityPoolId];
AWSServiceConfiguration *configuration1 = [[AWSServiceConfiguration alloc] initWithRegion:CognitoIdentityUserPoolRegion credentialsProvider:credentialsProvider];

[AWSServiceManager defaultServiceManager].defaultServiceConfiguration = configuration1;

[AWSCognitoIdentityUserPool registerCognitoIdentityUserPoolWithConfiguration: configuration1 userPoolConfiguration:configuration forKey:@"UserPool"];

AWSCognitoIdentityUserPool *pool = [AWSCognitoIdentityUserPool CognitoIdentityUserPoolForKey:@"UserPool"];

pool.delegate = self;
于 2018-10-19T09:52:32.590 回答
0

2天后,我明白了。

 AWSCognitoCredentialsProvider *credentialsProvider = [[AWSCognitoCredentialsProvider alloc] initWithRegionType:CognitoIdentityUserPoolRegion
                                                                                                    identityPoolId:CognitoIdentityPoolId identityProviderManager:pool];

需要设置identityProviderManager。非常感谢你。

于 2018-10-24T01:09:40.020 回答