【问题标题】:failed to get credential.state and getCredentialStateForUserID未能获得 credential.state 和 getCredentialStateForUserID
【发布时间】:2020-01-10 23:05:11
【问题描述】:

我无法从方法 getCredentialStateForUserID 中获取 credentialState,而其他成员返回良好。

我在 iPhone 8、iOS 13 模拟器上运行了该应用程序。

- (void)authorizationController:(ASAuthorizationController *)controller didCompleteWithAuthorization:(ASAuthorization *)authorization {

    if ([authorization.credential isKindOfClass:[ASAuthorizationAppleIDCredential class]]) {
        ASAuthorizationAppleIDCredential *credential = authorization.credential;

        NSString *state = credential.state;
        NSString *userID = credential.user;
        [[NSUserDefaults standardUserDefaults] setValue:userID forKey:currentAppleId];

        NSPersonNameComponents *fullName = credential.fullName;
        NSString *email = credential.email;
        NSString *authorizationCode = [[NSString alloc] initWithData:credential.authorizationCode encoding:NSUTF8StringEncoding];
        // refresh token

        NSString *identityToken = [[NSString alloc] initWithData:credential.identityToken encoding:NSUTF8StringEncoding];
        // access token

        ASUserDetectionStatus realUserStatus = credential.realUserStatus;

        NSLog(@"state: %@", state);
        NSLog(@"userID: %@", userID);
        NSLog(@"fullName: %@", fullName);
        NSLog(@"email: %@", email);
        NSLog(@"authorizationCode: %@", authorizationCode);
        NSLog(@"identityToken: %@", identityToken);
        NSLog(@"realUserStatus: %@", @(realUserStatus));

        ASAuthorizationAppleIDProvider *appleIDProvider = [ASAuthorizationAppleIDProvider new];

        if (userID) {
            NSString* __block errorMsg = nil;
            [appleIDProvider getCredentialStateForUserID:userID completion:^(ASAuthorizationAppleIDProviderCredentialState credentialState, NSError * _Nullable error) {
                switch (credentialState) {
                    case ASAuthorizationAppleIDProviderCredentialRevoked:
                        errorMsg = @"revoked";
                        break;
                    case ASAuthorizationAppleIDProviderCredentialAuthorized:
                        errorMsg = @"completed well";
                        break;
                    case ASAuthorizationAppleIDProviderCredentialNotFound:
                        errorMsg = @"credential not found";
                        break;
                }
                dispatch_async(dispatch_get_main_queue(), ^{
                    NSLog(@"SignInWithApple state");
                    NSLog(@"%@", errorMsg);
                });
            }];
        }
    }
}

状态:(空)

realUserStatus: 1 (ASUserDetectionStatusUnknown)

为什么我会收到这个不合适的值? 任何其他值都会很好地返回。

我收到了这个错误

2019-09-09 16:28:05.859082+0900 AppleSignin[57581:3353025] [核心] 凭据状态请求返回错误:Error Domain=AKAuthenticationError Code=-7001 "(null)"

【问题讨论】:

  • 请问您解决了这个问题吗?如果可以,您可以分享您的解决方案吗?
  • 只是为了快速检查 1. 添加 - (void)authorizationController:(ASAuthorizationController *)controller didCompleteWithAuthorization:(ASAuthorization *)authorization { ... [[NSUserDefaults standardUserDefaults] setValue:userID forKey:appleUserId]; 2. 在方法中调用getCredentialStateForUserID - (void)applicationWillEnterForeground:(UIApplication *)application { }
  • 我也遇到了同样的情况,你找到解决办法了吗?
  • @ZoltanMagyar 你找到解决办法了吗?
  • 您是否设法在这里找出原因?我遇到了同样的问题,无法隔离问题。它发生在设备上,甚至通过试飞的分布配置文件发生。

标签: objective-c ios13 apple-sign-in


【解决方案1】:

同样的事情发生在我身上,经过一些测试,我发现当我使用设备进行测试时它开始工作。此外,在模拟器上,它总是会每次都询问姓名/电子邮件,即使用户已经同意了。当我切换到设备时,这也得到了解决:第一次之后,用户不会被要求再次授予权限,而是必须提供他的 PIN/密码才能登录。 希望这会有所帮助!

【讨论】:

  • 在设备上完全相同的代码,我得到“授权”而不是“未找到”-> 模拟的绝对经典无法击败真实设备
  • 我遇到了同样的问题,但在设备上:(
猜你喜欢
  • 2015-05-15
  • 2016-06-13
  • 2013-04-19
  • 2017-07-11
  • 1970-01-01
  • 2018-06-02
  • 2013-09-25
  • 2017-09-27
  • 2017-01-08
相关资源
最近更新 更多