这是我的场景。
Someone has iPhone and iPad (iOS 13.0 or later), and he signed up with same appleID.
And he `sign in with apple` in his iPhone and try to `sign in with apple` again in his iPad.
我不希望他通过编辑他的姓名或检查共享或在他触摸登录按钮时两次隐藏他的电子邮件来“用苹果登录”两次。
我从示例代码中找到了一些可以帮助我上面的场景的代码
func performExistingAccountSetupFlows() {
// Prepare requests for both Apple ID and password providers.
let requests = [ASAuthorizationAppleIDProvider().createRequest(),
ASAuthorizationPasswordProvider().createRequest()]
// Create an authorization controller with the given requests.
let authorizationController = ASAuthorizationController(authorizationRequests: requests)
authorizationController.delegate = self
authorizationController.presentationContextProvider = self
authorizationController.performRequests()
}
我发现这ASPasswordCredential将帮助我定义凭据用户
- 首先,我应该实现保存 userIdentifier
iCloud Keychain吗?那我需要添加Keychain group Capability吗? - 首先,我真的不知道将该
performExistingAccountSetupFlows功能放在哪里。我想在用户触摸按钮时显示 AuthorizationController。所以我尝试了这种方法。
@available(iOS 13.0, *)
@objc private func handleAuthorizationAppleIDButtonPress() {
let appleIDProvider = ASAuthorizationAppleIDProvider()
appleIDProvider.getCredentialState(
forUserID: KeychainItem.currentUserIdentifier ?? "") { [weak self] (credentialState, error) in
guard let `self` = self else { return }
log.debugPrint(KeychainItem.currentUserIdentifier ?? "nil")
switch credentialState {
case .authorized:
// The Apple ID credential is valid. Show Home UI Here
// MARK: Existing iCloud keychain
self.performExistingAccountSetupFlows()
break
case .revoked, .notFound:
let request = appleIDProvider.createRequest()
request.requestedScopes = [
.fullName,
.email
]
let controller = ASAuthorizationController(authorizationRequests: [request])
controller.delegate = self
controller.presentationContextProvider = self
controller.performRequests()
break
default:
break
}
}
}
这并不符合我的意图。
有没有好心的老师可以回答我的问题?
谢谢你。