Sign in with Apple - Different behaviour Simulator

2020-07-10 10:56发布

问题:

I'm trying to setup Sign-in with Apple with Xcode (Beta 11.0 beta 6).

Works great on simulator, but when I run it on my iPhone (iOS 13.1), I don't get the same display.

On Simulator:

On iPhone:

This is how I call my "Sign in with Apple":

- (IBAction)signInWithApple:(id)sender {
    if (@available(iOS 13.0, *)) {
        ASAuthorizationAppleIDProvider *appleIDProvider = [[ASAuthorizationAppleIDProvider alloc] init];
        ASAuthorizationAppleIDRequest *request = [appleIDProvider createRequest];
        request.requestedScopes = @[ASAuthorizationScopeFullName,ASAuthorizationScopeEmail];
        ASAuthorizationController *authorizationController = [[ASAuthorizationController alloc] initWithAuthorizationRequests:@[request]];
        authorizationController.delegate = self;
        authorizationController.presentationContextProvider = self;
        [authorizationController performRequests];
    } else {
        // Fallback on earlier versions
    }
}

Based on my debug I know that in both cases the code is executed and the email + fullname scope are set in the authorizationController.

I expect in both cases to see the Sign in with apple and to be ask about my fullname and if I wanna Hide My email...

But it only happen on simulator. On iPhone I just "continue", get my face recognize... And that's it.

In both case this is called after:

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

    ASAuthorizationAppleIDCredential *appleIDCredential = authorization.credential;
...

But in case of Simulator I'm able to get values for

"appleIDCredential.identityToken"
"appleIDCredential.email"
"appleIDCredential.fullName"

While on my iPhone I'm only able to get values for

"appleIDCredential.identityToken"

Thank you for your help ! :)

PS: In both cases I tried to connect with the same Apple Account, so I tried to look about apple configuration but I'm not sure what's wrong if it's the problem.

回答1:

It seems on Simulator you see sign-up flow (first time user experience) and on the device you've already passed through sign-up and now you see log-in flow (returning user experience). I'm not sure why doesn't simulator display the log-in flow, but it works the same way for me as well.

According to documentation and this thread you won't get user info (email and full name) on completion of the log-in flow:

Ensure that your app relays the credentials and user information to your app servers. The API collects this information and shares it with your app the first time the user logs in to the app using Sign in with Apple. If the user then uses Sign in with Apple on another device, the API doesn't ask for the user’s name or email again. It collects the information again only if the user stops using Sign in with Apple and later reconnects to your app.

Because the user’s information isn’t shared with your app in any subsequent API calls, your app should store it locally, immediately after you receive it from the API response. In case of subsequent failures in your process or network, you can read the information from local storage and try processing it again.

There is a way to return to the sign-up flow on you device by revoking usage of Apple ID by your application. To do it you can go to device Settings → Passwords & Accounts → iCloud → Password & Security → Apps Using Your Apple ID → [NameOfYourApp] App → Stop Using Apple ID → Stop Using.

You also can visit your Apple ID App Security page to do it. It should look like this:

I took the image and some hints from What the Heck is Sign In with Apple?