经过身份验证后如何注销Apple

我的应用程序具有“使用Apple登录”帐户功能。我想知道苹果帐户是否有退出功能。

我尝试了以下方法,但没有成功

    let request = ASAuthorizationAppleIDProvider().createRequest()

    request.requestedOperation = .operationLogout

    let authorizationController = ASAuthorizationController(authorizationRequests: [request])

    authorizationController.performRequests()
gyglove2008 回答:经过身份验证后如何注销Apple

Apple当前仅允许用户执行注销(iOS / watchOS / tvOS)或显示为对我们的撤消权限。他们建议您在使用证书检查撤销之前,先获取凭据的状态,以及是否已删除所有本地信息(删除存储在用户标识符中的用户标识符)(并可能在需要时更改UI;例如,显示登录名)视图)。

        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.
            }
        default:
            break
        }
    }

您可以在注销时向用户提供提示,指导他们也撤消其设备的设置并收听更改通知。

,

您需要从钥匙串中删除现有项目。

这是我的示例代码,使用 Apple 示例代码。
您可以从 Apple

获取示例代码

Apple 建议您在使用前获取凭据的状态以检查是否已撤销,如果已发生,则删除任何本地信息

struct KeychainItem {

    
    init(service: String,account: String,accessGroup: String? = nil) {
        self.service = service
        self.account = account
        self.accessGroup = accessGroup
    }

    static func deleteUserIdentifierFromKeychain() {
        do { //please change service id to your bundle ID 
            try KeychainItem(service: "com.example.apple-samplecode",account: "userIdentifier").deleteItem()
        } catch {
            print("Unable to delete userIdentifier from keychain")
        }
    }

   func deleteItem() throws {
        // Delete the existing item from the keychain.
        let query = KeychainItem.keychainQuery(withService: service,account: account,accessGroup: accessGroup)
        let status = SecItemDelete(query as CFDictionary)
        
        // Throw an error if an unexpected status was returned.
        guard status == noErr || status == errSecItemNotFound else { throw KeychainError.unhandledError }
    }
本文链接:https://www.f2er.com/3110503.html

大家都在问