Created
December 9, 2019 02:03
-
-
Save dengue8830/27d2879229b665768e626ed9c1db8204 to your computer and use it in GitHub Desktop.
Apple swift ios sign in snippet
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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