无法获取credential.state和getCredentialStateForUserID [英] failed to get credential.state and getCredentialStateForUserID

查看:599
本文介绍了无法获取credential.state和getCredentialStateForUserID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法从方法getCredentialStateForUserID中获取credentialState,而其他成员也很好地返回了.

I can't get the credentialState from method getCredentialStateForUserID while other members got returned well.

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

I ran the app on iPhone 8, iOS 13 simulator.

- (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)

realUserStatus: 1 (ASUserDetectionStatusUnknown)

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

Why am I receiving this inappropriate values? any other values get returned well.

我收到此错误

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

2019-09-09 16:28:05.859082+0900 AppleSignin[57581:3353025] [core] Credential State request returned with error: Error Domain=AKAuthenticationError Code=-7001 "(null)"

推荐答案

我发生了同样的事情,经过一些测试,我发现使用设备进行测试时它开始工作.同样,即使用户已经授予了Simulator的权限,每次都会要求输入名称/电子邮件.当我切换到设备时,此问题也得到解决:第一次后,将不再要求用户再次授予权限,而是必须提供PIN/密码才能登录. 希望这会有所帮助!

Same happened to me and after some testing I discovered that it started to work when I used a device for testing. Also, on Simulator it would ALWAYS ask for Name/Email every time, even though the user had already granted that. This was also solved when I switched to a device: after the first time, the user won't get asked to grant permissions again, instead he will have to provide his PIN/Password to login. Hope this helps!

这篇关于无法获取credential.state和getCredentialStateForUserID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆