failed to get credential.state and getCredentialStateForUserID

一曲冷凌霜 提交于 2020-06-15 09:59:12

问题


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

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);
                });
            }];
        }
    }
}

state: (null)

realUserStatus: 1 (ASUserDetectionStatusUnknown)

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

and I'm getting this error

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


回答1:


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!



来源:https://stackoverflow.com/questions/57849628/failed-to-get-credential-state-and-getcredentialstateforuserid

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!