AWSCognitoCredentialsProvider.credentialsWithRegionType被删除。用什么代替?

时间:2016-02-17 09:45:01

标签: amazon-web-services amazon-cognito

我是iOS应用中的AWS Cognito和AWSCognitoDataset。

我正在调用registerCognitoWithConfiguration()但这已被弃用。 而应该使用init()。但我认为我需要使用的那个需要一个我无法访问的identityId,直到我使用credentialsProvider来调用getIdentityId() - 这是一个catch 22。

那么,我该如何替换registerCognitoWithConfiguration()?

Digits.sharedInstance().authenticateWithViewController( ...
{session, error in
if session != nil {
    self.completeDigitsLogin()
} else {
    ...
}

func completeDigitsLogin() {
    if let session = Digits.sharedInstance().session() {
        AWSCognitoCredentialsProvider.credentialsWithRegionType(
            Constants.COGNITO_REGIONTYPE,
            accountId:Constants.AWS_ACCOUNT_ID,
            identityPoolId:Constants.COGNITO_IDENTITY_POOL_ID,
            unauthRoleArn:"",
            authRoleArn:Constants.COGNITO_ARN_AUTH_ROLE,
            logins:["www.digits.com": makeTwitterSessionString(session)])

        let conf = AWSServiceConfiguration(
            region:Constants.COGNITO_REGIONTYPE,
            credentialsProvider:credentialsProvider)

        AWSCognito.registerCognitoWithConfiguration(config, forKey:"main")

        credentialsProvider.getIdentityId().continueWithBlock {
            (task:AWSTask!) -> AnyObject! in

           let cognitoId = task.result as! String
           print("CognitoId = \(cognitoId)")

           let cognitoSync = AWSCognito(forKey:"main")
           self.dataset = cognitoSync.openOrCreateDataset("Candidate")
           self.dataset.setString(session.phoneNumber, forKey:"phone")
           self.synchronizeDataset()
        return nil
        }
    }
}