2016-05-15 8 views
1

verfolge ich dieses Blog-Post von amazon: https://mobile.awsblog.com/post/Tx2UQN4KWI6GDJL/Understanding-Amazon-Cognito-AuthenticationAufruf GetID mit amazon cognito in ios

Ich habe dies ein:

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

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

AWSServiceManager.defaultServiceManager.defaultServiceConfiguration = configuration; 

In iOS Wie rufe ich GetID?

+0

zu Nicht selbst ist nicht verwenden der IdentityPool-Name aber stattdessen Die Pool-ID, die im Beispielcode bereitgestellt wird, würde in der Tat helfen – cdub

Antwort

3

Sie müssen getId und aktualisieren Sie dann die Anmeldeinformationen. Zuerst tun:

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

Swift:

// 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 
} 

Dann aktualisieren:

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

Von Dokumentation HERE

+0

ist nicht schon alt bftask? – cdub

+0

Ist dies noch relevant: https://mobile.awsblog.com/post/Tx2UQN4KWI6GDJL/Understanding-Amazon-Cognito-Authentication – cdub

Verwandte Themen