Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Apple swift ios sign in snippet
// At the top of the file
import AuthenticationServices
// ...
@objc
func appleSignIn(resolve: RCTPromiseResolveBlock, reject: RCTPromiseRejectBlock) {
if #available(iOS 13.0, *) {
let appleIDProvider = ASAuthorizationAppleIDProvider()
let request = appleIDProvider.createRequest()
request.requestedScopes = [.fullName, .email]
let authorizationController = ASAuthorizationController(authorizationRequests: [request])
authorizationController.delegate = self as? ASAuthorizationControllerDelegate
authorizationController.performRequests()
} else {
// Fallback on earlier versions
}
}
@available(iOS 13.0, *)
func authorizationController(controller: ASAuthorizationController,
didCompleteWithAuthorization authorization: ASAuthorization) {
if let appleIDCredential = authorization.credential as? ASAuthorizationAppleIDCredential {
let userIdentifier = appleIDCredential.user
let fullName = appleIDCredential.fullName
let email = appleIDCredential.email
print("User id is \(userIdentifier) , Full Name is \(String(describing: fullName)) , Email id is \(String(describing: email))")
}
}
@available(iOS 13.0, *)
func authorizationController(controller: ASAuthorizationController, didCompleteWithError error: Error) {
print("apple-signin-error: \(error)")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.