Skip to content

Instantly share code, notes, and snippets.

@dengue8830
Created December 9, 2019 02:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dengue8830/27d2879229b665768e626ed9c1db8204 to your computer and use it in GitHub Desktop.
Save dengue8830/27d2879229b665768e626ed9c1db8204 to your computer and use it in GitHub Desktop.
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