这是我的情况。
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
将帮助我定义凭据用户
- 首先,我应该在
iCloud Keychain
中实现保存userIdentifier吗?那我需要添加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
}
}
}
这不符合我的预期。
有什么好心的老师可以回答我的问题吗?
谢谢。