首页 > 解决方案 > 如何使用苹果注销登录

问题描述

使用Apple登录时,我想知道如何注销。我知道的两种撤销方法

[1] 打开您的应用程序后

  1. 打开“设置”应用,然后点击 [您的姓名]。
  2. 点击密码和安全
  3. 点击使用您的 Apple ID 的应用程序。
let authorizationAppleIDProvider = ASAuthorizationAppleIDProvider()

  authorizationAppleIDProvider.getCredentialState(forUserID: "currentUserIdentifier") { (credentialState: ASAuthorizationAppleIDProvider.CredentialState, error: Error?) in
    if let error = error {
      print(error)
      // Something went wrong check error state
      return
    }
    switch (credentialState) {
    case .authorized:
      //User is authorized to continue using your app
      break
    case .revoked:
      //User has revoked access to your app
      break
    case .notFound:
      //User is not found, meaning that the user never signed in through Apple ID
      break
    default: break
    }
  }

之后运行应用程序时如何通过此代码知道

[2] 当您的应用程序正在运行时

let notificationCenter = NotificationCenter.default
  let sessionNotificationName = NSNotification.Name.ASAuthorizationAppleIDProviderCredentialRevoked

  appleIDSessionObserver = notificationCenter.addObserver(forName: sessionNotificationName, object: nil, queue: nil) { (notification: Notification) in
    //Sign user out
  }

当用户会话更改时,此代码会在 credentialState 被撤销时发出通知。

我很好奇的是 [2] 当您的应用程序运行时,在什么情况下用户会话在应用程序中被撤销?例如,如果你按下注销按钮,credentialState 变为撤销,你会收到通知并执行注销功能,对吧?如何在使用应用程序的情况下撤销 appleId CredentialState?

标签: iosswift

解决方案


推荐阅读