【发布时间】:2017-03-12 11:57:58
【问题描述】:
我是第一次尝试使用 Mobile Hub。我创建了一个示例应用程序,并且用户仅通过 facebook 登录。我的主要问题是
- 如何确定这是用户第一次登录还是之前存在
- 如何将数据同步到 AWS cognito 数据集
为了解决第一个问题,我想出了这个解决方案来检查用户数据集是否为空,那么这是用户第一次加入。
为了在应用程序委托中执行此操作,didFinishLaunchingWithOptions:
AWSCognitoCredentialsProvider *credentialsProvider = [[AWSCognitoCredentialsProvider alloc]
initWithRegionType:AWSRegionUSEast1
identityPoolId:@"us-east-1:pool id is here"];
AWSServiceConfiguration *configuration = [[AWSServiceConfiguration alloc] initWithRegion:AWSRegionUSEast1 credentialsProvider:credentialsProvider];
[AWSServiceManager defaultServiceManager].defaultServiceConfiguration = configuration;
后来我尝试这样做:
AWSCognito *syncClient = [AWSCognito defaultCognito];
// Create a record in a dataset and synchronize with the server
AWSCognitoDataset *dataset = [syncClient openOrCreateDataset:@"Sample"];
[dataset setString:@"test2" forKey:@"test"];
[[dataset synchronize] continueWithBlock:^id(AWSTask *task) {
// Your handler code here
return nil;
}];
[dataset synchronize];
服务器上没有用户的数据集。我正在尝试创建这个数据集。但问题是 [AWSCognito defaultCognito] 返回 null。我检查了文档,上面写着:
返回单例服务客户端。如果单例对象没有 存在,SDK 实例化默认服务客户端 [AWSServiceManager 中的 defaultServiceConfiguration 默认服务管理器]。对此对象的引用由 SDK,无需手动保留。如果 凭证提供者不是 AWSCognitoCredentials 的实例 提供者。
我不确定我错过了什么。为什么当我调用这个单例时它返回 null!
如何检查凭证提供者是否是 AWSCognitoCredentials 提供者的实例?
我在 Cognito 服务中签入了身份浏览器。新身份已创建,但没有数据集。会不会是与角色和 IAM 相关的东西?
【问题讨论】:
标签: ios amazon-web-services amazon-cognito aws-mobilehub