How to Sign Out of Apple After Being Authenticated

核能气质少年 提交于 2020-05-13 09:02:19

问题


My app has a "Sign in with the Apple" account feature. I am wondering if there is sign out feature from the Apple account.

I tried the below but doesn't get success

    let request = ASAuthorizationAppleIDProvider().createRequest()

    request.requestedOperation = .operationLogout

    let authorizationController = ASAuthorizationController(authorizationRequests: [request])

    authorizationController.performRequests()

回答1:


Apple only allows currently for the user to perform a signout (iOS/watchOS/tvOS) or shown as a revoke of permissions to us. They recommend you get the state of the credentials before use to check for revoke and if that has occurred to delete any local information (Remove the user identifier where ever you have it stored) (And possibly change UI if needed; For example like showing login view).

        let appleIDProvider = ASAuthorizationAppleIDProvider()
    appleIDProvider.getCredentialState(forUserID: KeychainItem.currentUserIdentifier) { (credentialState, error) in
        switch credentialState {
        case .authorized:
            // The Apple ID credential is valid.
            break
        case .revoked:
            // The Apple ID credential is revoked.
            break
        case .notFound:
            // No credential was found, so show the sign-in UI.
            break
        default:
            break
        }
    }

You could provide a prompt to the user on signout guiding them to revoke in their device's settings as well and listen for the change notification.



来源:https://stackoverflow.com/questions/58836179/how-to-sign-out-of-apple-after-being-authenticated

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!