Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/95.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在ios中使用amazon cognito调用GetID_Ios_Amazon Web Services_Amazon Cognito_Aws Mobilehub - Fatal编程技术网

在ios中使用amazon cognito调用GetID

在ios中使用amazon cognito调用GetID,ios,amazon-web-services,amazon-cognito,aws-mobilehub,Ios,Amazon Web Services,Amazon Cognito,Aws Mobilehub,我下面是亚马逊的这篇博文: 我已建立了以下设置: AWSCognitoCredentialsProvider *credentialsProvider = [[AWSCognitoCredentialsProvider alloc] initWithRegionType:AWSRegionUSEast1 identityPoolId:@"IdentityPool"]; AWSServiceConfiguration *configuration = [[AWSServiceConfigurat

我下面是亚马逊的这篇博文:

我已建立了以下设置:

AWSCognitoCredentialsProvider *credentialsProvider = [[AWSCognitoCredentialsProvider alloc] initWithRegionType:AWSRegionUSEast1 identityPoolId:@"IdentityPool"];

AWSServiceConfiguration *configuration = [[AWSServiceConfiguration alloc] initWithRegion:AWSRegionUSEast1 credentialsProvider:credentialsProvider];

AWSServiceManager.defaultServiceManager.defaultServiceConfiguration = configuration;

在iOS中如何调用GetID?

您必须
GetID
,然后刷新凭据。首先要做:

Obj-C:

// Retrieve your Amazon Cognito ID
[[credentialsProvider getIdentityId] continueWithBlock:^id(AWSTask *task) {
    if (task.error) {
        NSLog(@"Error: %@", task.error);
    }
    else {
        // the task result will contain the identity id
        NSString *cognitoId = task.result;
    }
    return nil;
}];
斯威夫特:

// Retrieve your Amazon Cognito ID
credentialsProvider.getIdentityId().continueWithBlock { (task: AWSTask!) -> AnyObject! in
    if (task.error != nil) {
        print("Error: " + task.error.localizedDescription)
    }
    else {
        // the task result will contain the identity id
        let cognitoId = task.result
    }
    return nil
}
然后刷新:

- (BFTask *)getIdentityId {
    if (self.identityId) {
        return [BFTask taskWithResult:self.identityid];
    } else {
        return [[BFTask taskWithResult:nil] continueWithBlock:^id(BFTask *task) {
            if (!self.identityId) {
                return [self refresh];
            }
            return [BFTask taskWithResult:self.identityid];
        }];
    }
}

- (BFTask *)refresh {
    return [[BFTask taskWithResult:nil] continueWithBlock:^id(BFTask *task) {
          // make a call to your backend, passing logins on provider
          MyLoginResult *result = [MyLogin login:user password:password withLogins:self.logins];
          // results should contain identityid and token, set them on the provider
          self.token = result.token;
          self.identityId = result.identityId;
          // not required, but returning the identityId is useful
          return [BFTask taskWithResult:self.identityid]; 
    }];
}

从文档

到self is,不要使用IdentityPool名称,而是使用示例代码中提供的池Id。这是否仍然相关: