Я знаю, что этот вопрос не задают в первый раз, но я застрял ... Я попытался войти в систему с помощью Apple, и у меня возникли проблемы с получением пользовательских данных, мой код выглядит следующим образом
import UIKit
import AuthenticationServices
class SignInWithAppleVC: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
setupProviderLoginView()
}
func setupProviderLoginView() {
let appleButton = ASAuthorizationAppleIDButton()
appleButton.frame = CGRect(x: 20, y: (Int(UIScreen.main.bounds.size.height) - 150), width: (Int(UIScreen.main.bounds.size.width) - 40), height: 50)
appleButton.addTarget(self, action: #selector(signInWithApple), for: .touchUpInside)
self.view.addSubview(appleButton)
}
@objc func signInWithApple() {
print("sign in with apple clicked")
let appleIdProvider = ASAuthorizationAppleIDProvider()
let request = appleIdProvider.createRequest()
request.requestedScopes = [.email,.fullName]
let authorizationController = ASAuthorizationController(authorizationRequests: [request])
authorizationController.delegate = self
authorizationController.presentationContextProvider = self
authorizationController.performRequests()
}
}
extension SignInWithAppleVC : ASAuthorizationControllerDelegate {
func authorizationController(controller: ASAuthorizationController, didCompleteWithError error: Error) {
let alert = UIAlertController(title: "ERROR", message: "\(error.localizedDescription)", preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "OK", style: .cancel, handler: nil))
present(alert, animated: true, completion: nil)
}
func authorizationController(controller: ASAuthorizationController, didCompleteWithAuthorization authorization: ASAuthorization) {
switch authorization.credential {
case let credentials as ASAuthorizationAppleIDCredential:
print(credentials.user) // Here we get results only first time
print(credentials.fullName?.givenName!)//
print(credentials.fullName?.familyName)//
//MARK: - Use credentials
case let credintials as ASPasswordCredential :
print(credintials.password)
default:
let alert = UIAlertController(title: "Apple SgnIn", message: "Something went wrong", preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "OK", style: .cancel, handler: nil))
present(alert, animated: true, completion: nil)
}
}
}
extension SignInWithAppleVC : ASAuthorizationControllerPresentationContextProviding {
func presentationAnchor(for controller: ASAuthorizationController) -> ASPresentationAnchor {
return view.window!
}
}
Проблема в том, что я получаю электронную почту, имя и фамилию только с первой попытки. но каждый раз я получаю ноль в ответ. Мне нужно получить доступ к Связке ключей для даты пользователя (если да, то как, пожалуйста) или любого другого решения ?. Любая помощь, ссылка, пример кода будут тепло оценены. заранее спасибо