Код: Выделить всё
private func _requestAppleLogin() {
let appleIDProvider = ASAuthorizationAppleIDProvider()
let request = appleIDProvider.createRequest()
request.requestedScopes = [.fullName, .email]
let authorizationController = ASAuthorizationController(authorizationRequests: [request])
authorizationController.delegate = self
authorizationController.performRequests()
}
func authorizationController(controller: ASAuthorizationController, didCompleteWithAuthorization authorization: ASAuthorization) {
if let appleIDCredential = authorization.credential as? ASAuthorizationAppleIDCredential {
if let data = appleIDCredential.identityToken {
let token = String(decoding: data, as: UTF8.self)
let firstName = appleIDCredential.fullName?.givenName ?? kEmptyString
let lastName = appleIDCredential.fullName?.familyName ?? kEmptyString
self.showHUD()
APPSESSION.loginWithApple(token: token, firstName: firstName, lastName: lastName) { [weak self] success, error in
guard let self = self else { return }
self.hideHUD(error: error)
guard success else { return }
self.moveToHome()
}
}
let userIdentifier = appleIDCredential.user
let fullName = appleIDCredential.fullName
let email = appleIDCredential.email
print("User id is \(userIdentifier) \n Full Name is \(String(describing: fullName)) \n Email id is \(String(describing: email))") }
}
Подробнее здесь: https://stackoverflow.com/questions/793 ... ce-restart
Мобильная версия