名称和邮件范围的ASAuthorizationAppleIDRequest返回nil值 [英] ASAuthorizationAppleIDRequest with name and mail scope returns nil values
问题描述
我正在用Apple实现登录,并注意到返回的ASAuthorizationAppleIDCredential
的email
和fullName
属性仅在此Apple ID的第一个登录中填充.在所有后续登录中,这些属性均为零.
I'm implementing Sign in with Apple and noticed that the email
and fullName
properties of the returned ASAuthorizationAppleIDCredential
are only filled on the very first Sign-In for this Apple ID. On all subsequent Sign-Ins those properties are nil.
这是iOS 13上的错误还是预期的行为?
Is this a bug on iOS 13 or expected behaviour?
这是我用来启动请求的代码:
Here is the code I'm using to start the request:
@available(iOS 13.0, *)
dynamic private func signInWithAppleClicked() {
let request = ASAuthorizationAppleIDProvider().createRequest()
request.requestedScopes = [.fullName, .email]
let controller = ASAuthorizationController(authorizationRequests: [request])
controller.delegate = self
controller.presentationContextProvider = self
controller.performRequests()
}
我正在通过此委托方法接收凭据:
I'm receiving the credential in this delegate method:
public func authorizationController(controller: ASAuthorizationController, didCompleteWithAuthorization authorization: ASAuthorization) {
guard let credential = authorization.credential as? ASAuthorizationAppleIDCredential else { return }
let userIdentifier = credential.user
let token = credential.identityToken
let authCode = credential.authorizationCode
let realUserStatus = credential.realUserStatus
let mail = credential.email // nil
let name = credential.fullName // nil
}
推荐答案
似乎是一个错误,但在Apple论坛上阅读了不同的帖子后,这似乎是预期的行为.
Seems like a bug but after reading different posts on apple forums it looks like this seems to be the expected behaviour.
有一些要点.
- 首次使用Apple登录(注册)时,请确保在后端上创建用户帐户.
-
万一服务器发生连接错误,请确保将用户详细信息保存在本地(因为下次无法使用此信息),并继续尝试在后端创建帐户.
- On the first time sign in with apple (signup) make sure to create user account on your backend.
In case of any connection error with your servers, make sure you save the user details locally (because you are not getting this next time) and keep retrying to create account on your backend.
要在设备上进行测试,您可以撤消应用程序的Apple ID登录.撤消后,下次它将像注册一样工作,您将获得诸如(电子邮件,姓名等)的详细信息.
For testing on device you can revoke your apple ID login for your app. After revoking it will work like a signup next time and you will get the details like (email, name, etc).
使用IOS 13撤消对设备的访问.
To revoke access on your device with IOS 13.
iPhone Settings > Apple Id > Password & Security > Apple ID logins > {YOUR APP} > Stop using Apple ID
这篇关于名称和邮件范围的ASAuthorizationAppleIDRequest返回nil值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!