使用Apple登录-行为不同的模拟器VS iPhone [英] Sign in with Apple - Different behaviour Simulator VS iPhone

查看:163
本文介绍了使用Apple登录-行为不同的模拟器VS iPhone的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Xcode(Beta 11.0 beta 6)与Apple设置登录.

在模拟器上效果很好, 但是当我在iPhone(iOS 13.1)上运行它时,却没有得到相同的显示.

在模拟器上:

在iPhone上:

这就是我所说的使用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
    }
}
 

基于我的调试,我知道在两种情况下都将执行代码,并在authorizationController中设置电子邮件+全名范围.

我希望在两种情况下都能看到使用Apple登录,并询问我的全名以及是否要隐藏我的电子邮件...

但是它仅在模拟器上发生.在iPhone上,我只是继续",让我的脸部识别……就是这样.

在这两种情况下,都将在以下情况下调用:

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

    ASAuthorizationAppleIDCredential *appleIDCredential = authorization.credential;
...
 

但是在模拟器的情况下,我可以获取

的值

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

在我的iPhone上,我只能获取的值

"appleIDCredential.identityToken"

谢谢您的帮助! :)

PS:在这两种情况下,我都尝试使用相同的Apple帐户进行连接,因此我尝试查看Apple配置,但是不确定问题出在哪里.

解决方案

在Simulator上,您似乎看到注册流程(首次用户体验),在已经通过注册的设备上,现在您看到了登录流程(返回用户体验).我不确定模拟器为什么不显示登录流程,但是对我来说,它的工作方式也相同.

根据文档

由于在随后的任何API调用中用户的信息均未与您的应用共享,因此您的应用应在从API响应收到信息后立即将其存储在本地.如果您的流程或网络出现后续故障,则可以从本地存储中读取信息,然后尝试再次进行处理.

有一种方法可以通过撤销应用程序对Apple ID的使用来返回设备上的注册流程. 为此,您可以转到设备设置→密码和密码;帐户→iCloud→密码&安全性→使用您的Apple ID的应用程序→[NameOfYourApp]应用程序→停止使用Apple ID的应用程序→停止使用.

您还可以访问 Apple ID应用程序安全性页面来进行此操作.看起来应该像这样:

我从使用Apple登录会带来什么麻烦?

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.

解决方案

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?

这篇关于使用Apple登录-行为不同的模拟器VS iPhone的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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