我是处理 AWS Web 服务的新手,我正在使用开放身份在 AWSCognitoCredentialsProvider 类的登录字典中发送 DeveloperAuthProviderName 和 Token,然后在 viecontroller 中我正在调用 lambda 函数,它在下面给了我错误。我使用了 CognitoSyncDemo App 并尝试通过 pod 导入所有框架,但结果是相同的。请帮我解决这个问题。
AWSiOSSDKv2 [错误] AWSCredentialsProvider.m 行:435 | __73-[AWSCognitoCredentialsProvider getCredentialsWithCognito:authenticated:]_block_invoke | GetCredentialsForIdentity 失败。错误是 [Error Domain=com.amazonaws.AWSCognitoIdentityErrorDomain Code=7“操作无法完成。(com.amazonaws.AWSCognitoIdentityErrorDomain 错误 7。)” UserInfo=0x1700778c0 {__type=InvalidParameterException, message=请提供有效的公共提供商}]
这是 Appdelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
AWSCognitoCredentialsProvider *credentialsProvider = [[AWSCognitoCredentialsProvider alloc] initWithRegionType:AWSRegionUSEast1 identityId:IdentityId identityPoolId:CognitoIdentityPoolId logins:@{DeveloperAuthProviderName:Token}];
AWSServiceConfiguration *configuration = [[AWSServiceConfiguration alloc] initWithRegion:AWSRegionUSEast1
credentialsProvider:credentialsProvider];
[[AWSServiceManager defaultServiceManager] setDefaultServiceConfiguration:configuration];
return YES;
}
这是 viewController 中 viewDidLoad 中的代码。
-(void)setUpCredentials{
//initWithRegionType:CognitoRegionType identityId:IdentityId identityPoolId:CognitoIdentityPoolId logins:@{DeveloperAuthProviderName:Token}
AZCDeveoper class inherit AWSEnhancedCognitoIdentityProvider class
AZCDeveloper * identity = [[AZCDeveloper alloc] initWithRegionType:CognitoRegionType identityId:IdentityId accountId:nil identityPoolId:CognitoIdentityPoolId logins:@{DeveloperAuthProviderName:Token}];
credentialsProvider = [[AWSCognitoCredentialsProvider alloc] initWithRegionType:CognitoRegionType
identityProvider:identity
unauthRoleArn:nil
authRoleArn:nil];
// [identity refresh];
}
这是在特定点击时调用的 lambda 函数
-(void)lamdaInvoker{
AWSLambdaInvoker *lambdaInvoker = [AWSLambdaInvoker defaultLambdaInvoker];
NSLog(@"LamdaInvoker:%@",lambdaInvoker);
[[lambdaInvoker invokeFunction:@"Hello"
JSONObject:@{@"": @""}] continueWithBlock:^id(BFTask *task) {
if (task.error) {
NSLog(@"Error: %@", task.error);
if ([task.error.domain isEqualToString:AWSLambdaInvokerErrorDomain]
&& task.error.code == AWSLambdaInvokerErrorTypeFunctionError) {
NSLog(@"Function error: %@", task.error.userInfo[AWSLambdaInvokerFunctionErrorKey]);
}
}
if (task.exception) {
NSLog(@"Exception: %@", task.exception);
}
if (task.result) {
NSLog(@"Result: %@", task.result);
dispatch_async(dispatch_get_main_queue(), ^{
});
}
return nil;
}];
}