ios - 如何使用苹果注销登录
问题描述
使用Apple登录时,我想知道如何注销。我知道的两种撤销方法
[1] 打开您的应用程序后
- 打开“设置”应用,然后点击 [您的姓名]。
- 点击密码和安全
- 点击使用您的 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?
解决方案
推荐阅读
- swift - 如何在 Swift 中从我的数据库生成状态变量?
- mongodb - 使用 Express、Mongoose 在嵌套的 MongoDB 文档中搜索
- javascript - 使用类创建的对象和对象之间的区别
- apache-spark - Spark Structured Streaming NOT 处理 Kafka 偏移量过期
- c++ - alignas() 对 sizeof() 的影响 - 强制性的?
- python-3.x - 在 Sympy 中表示一个常量符号,使其不是 free_symbol
- android - React Native - Android - tabNavigator 内 stackNavigator 中的keyboardavoidingView 推动bottomTabBar(笨拙的行为)
- python - Python数学问题我的结果非常接近示例但机器人相同
- c - int i 在这个特定程序的 for 循环中(在 scanf 和 sum 中)做了什么?
- awk - 模式匹配/排除(awk/sed)