2015-03-24 90 views
1

我想通过在iOS 8 Swift应用程序的应用程序委托中添加以下代码片段来初始化以创建默认服务配置。亚马逊AWS AWSCognitoCredentialsProvider初始化错误

遵医嘱亚马逊教程here我使用下面的代码行:

//AWS Service Config 
let credentialsProvider = AWSCognitoCredentialsProvider(
    regionType: AWSRegionType.USEast1, identityPoolId: "us-east-13453454-92d1-234234-234234-3434") 

let defaultServiceConfiguration = AWSServiceConfiguration(
    region: AWSRegionType.USEast1, credentialsProvider: credentialsProvider) 

AWSServiceManager.defaultServiceManager().defaultServiceConfiguration = defaultServiceConfiguration 

但是代码将无法正常编译,Xcode中说我“在电话中缺少论据参数‘identityId’”

首先,这段代码直接来自Amazon的教程,也没有identiyID,只是一个identitypoolid(在我的代码中混杂)。

我能做些什么来解决这个问题?

+0

这听起来像你可能没有最新版本iOS的SDK的。请确保您使用的是最新版本,因为并非所有版本都支持简化的构造函数。 – 2015-03-24 23:29:34

回答

0

我不知道你使用的是正确的初始化器,尝试 -

let credentialsProvider = AWSCognitoCredentialsProvider.credentialsWithRegionType(
    AWSRegionType.USEast1, 
    accountId: cognitoAccountId, 
    identityPoolId: cognitoIdentityPoolId, 
    unauthRoleArn: cognitoUnauthRoleArn, 
    authRoleArn: nil) 
    let defaultServiceConfiguration = AWSServiceConfiguration(region: AWSRegionType.USEast1, credentialsProvider: credentialsProvider) 
    AWSServiceManager.defaultServiceManager().setDefaultServiceConfiguration(defaultServiceConfiguration) 
+0

这是初始化credentialsProvider的方法之一。有一个更新的简化版本,只需要identityPoolId。请参阅获取凭证下的Objective C部分http://docs.aws.amazon.com/cognito/latest/developerguide/step1-getting-started.html。 – 2016-03-21 00:02:31

0
let cognitoIdentityPoolId = "us-east-XXXXXXXX" 

{

let credentialsProvider = AWSCognitoCredentialsProvider(regionType: .USEast1, identityPoolId: cognitoIdentityPoolId) 
let configuration = AWSServiceConfiguration(region: .USEast1, credentialsProvider: credentialsProvider) 

    AWSServiceManager.defaultServiceManager().defaultServiceConfiguration = configuration