我无法从 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] [核心] 凭据状态请求返回错误:错误域=AKAuthenticationError 代码=-7001“(空)”