Как решить проблему с клавиатурой при входе в систему "Войти через Apple" iOS 13 с помощью UIKit?
Я интегрировал в свой проект "Войти через Apple". Но после интеграции у меня возникает странная проблема при попытке войти в систему с использованием идентификатора Apple. Основная проблема - клавиатура появляется после завершения входа в систему.
Когда я пытаюсь войти в систему, он запрашивает двухфакторную аутентификацию, а затем появляется.
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
self.setupSOAppleSignIn()
}
func setupSOAppleSignIn() {
let btnAuthorization = ASAuthorizationAppleIDButton()
btnAuthorization.frame = CGRect(x: 0, y: 0, width: 200, height: 40)
btnAuthorization.center = self.view.center
btnAuthorization.addTarget(self, action: #selector(actionHandleAppleSignin), for: .touchUpInside)
self.view.addSubview(btnAuthorization)
}
@objc func actionHandleAppleSignin() {
let appleIDProvider = ASAuthorizationAppleIDProvider()
let request = appleIDProvider.createRequest()
request.requestedScopes = [.fullName, .email]
let authorizationController = ASAuthorizationController(authorizationRequests: [request])
authorizationController.delegate = self
authorizationController.presentationContextProvider = self
authorizationController.performRequests()
}
extension ViewController: ASAuthorizationControllerDelegate {
// ASAuthorizationControllerDelegate function for authorization failed
func authorizationController(controller: ASAuthorizationController, didCompleteWithError error: Error) {
print(error.localizedDescription)
}
// ASAuthorizationControllerDelegate function for successful authorization
func authorizationController(controller: ASAuthorizationController, didCompleteWithAuthorization authorization: ASAuthorization) {
if let appleIDCredential = authorization.credential as? ASAuthorizationAppleIDCredential {
// Create an account as per your requirement
let appleId = appleIDCredential.user
let appleUserFirstName = appleIDCredential.fullName?.givenName
let appleUserLastName = appleIDCredential.fullName?.familyName
let appleUserEmail = appleIDCredential.email
//Write your code
} else if let passwordCredential = authorization.credential as? ASPasswordCredential {
let appleUsername = passwordCredential.user
let applePassword = passwordCredential.password
//Write your code
}
}
}
extension ViewController: ASAuthorizationControllerPresentationContextProviding {
//For present window
func presentationAnchor(for controller: ASAuthorizationController) -> ASPresentationAnchor {
return self.view.window!
}
}
Я использовал эти два руководства для обучения.
https://www.raywenderlich.com/4875322-sign-in-with-apple-using-swiftui
https://www.spaceotechnologies.com/sign-in-with-apple-ios-tutorial/