Home > OS >  Is there a way to determine if user is singing in or up using Apple Sign In
Is there a way to determine if user is singing in or up using Apple Sign In

Time:12-28

When the user is signing in / up using Apple Sign In is there a way to determine whether the user already signed up once using Apple Sign In to this app or it is his first time ( If the app in Apps Using Apple ID list in iPhone Settings )?

enter image description here

I want to know whether I need to sign in the user in the server side or continue to sign up flow after

func authorizationController(controller: ASAuthorizationController, didCompleteWithAuthorization authorization: ASAuthorization)

is called.

CodePudding user response:

You can check for existing login details on app launch using the app delegate:

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
let appleIDProvider = ASAuthorizationAppleIDProvider()
appleIDProvider.getCredentialState(forUserID: KeychainItem.currentUserIdentifier) { (credentialState, error) in
    switch credentialState {
    case .authorized:
        break // The Apple ID credential is valid.
    case .revoked, .notFound:
        // The Apple ID credential is either revoked or was not found, so show the sign-in UI.
        DispatchQueue.main.async {
            self.window?.rootViewController?.showLoginViewController()
        }
    default:
        break
    }
}
return true

}

Source: https://developer.apple.com/documentation/sign_in_with_apple/implementing_user_authentication_with_sign_in_with_apple

  • Related