我很高兴将 Cognito Sync 与我的预发布应用程序 (iOS/Objective-C) 一起使用,并通过 Facebook 登录。但是,在提交 Apple App Store 审核后,我被要求删除 Facebook 登录。我认为这很简单——只需更改 unauth 角色策略以匹配 auth 用户并绕过与 Facebook 身份验证有关的任何事情。
但是,现在我发现 identityId 在会话之间发生了变化。它的行为类似于会话 ID。这是一个令人头疼的问题,因为我的应用程序使用 identityId 作为 DynamoDB 中的哈希键。因此,例如,DynamoDB 搜索当前用户最近的活动仅显示当前会话的历史记录,而不是预期的所有历史记录。
我正在使用示例应用程序的代码来获取 identityId - 它似乎被正确分配。基于示例的 AWSIdentityManager.m,下面是 AppDelegate.m 里面的一部分didFinishLaunchingWithOptions
:
AWSCognitoCredentialsProvider *credentialsProvider = [[AWSCognitoCredentialsProvider alloc] initWithRegionType:AMAZON_COGNITO_REGION
identityPoolId:AMAZON_COGNITO_IDENTITY_POOL_ID];
AWSServiceConfiguration *configuration = [[AWSServiceConfiguration alloc] initWithRegion:AMAZON_COGNITO_REGION
credentialsProvider:credentialsProvider];
AWSServiceManager.defaultServiceManager.defaultServiceConfiguration = configuration;
[[credentialsProvider getIdentityId] continueWithBlock:^id(AWSTask *task) {
if (task.error) {
NSLog(@"Error: Could not obtain identity id: %@", task.error);
}
else {
// the task result will contain the identity id
NSString *cognitoId = task.result;
NSLog(@"Got the identity ID as %@", cognitoId);
// Don't change the ID
NSString *oldId = [[NSUserDefaults standardUserDefaults] objectForKey:NSUD_COGNITO_ID];
if (!oldId) {
[[NSUserDefaults standardUserDefaults] setObject:cognitoId forKey:NSUD_COGNITO_ID];
[[NSUserDefaults standardUserDefaults] synchronize];
} else {
NSLog(@"Old = %@, New = %@, Keeping old", oldId, cognitoId);
}
}
return nil;
}];
我不断收到新旧身份不一样的信息。此外,当我签入 Cognito Sync 时,无法再找到旧身份。
现在没有使用 Facebook 登录提供程序,我如何确保 identityId 不会在会话等之间发生变化?有人可以阐明为什么会发生这种变化吗?我已经确认我没有清除代码中任何地方的钥匙串。