Ios Apple登录始终返回。未找到
我创建了苹果登录,就像 我觉得一切都很好Ios Apple登录始终返回。未找到,ios,swift,xcode,apple-sign-in,Ios,Swift,Xcode,Apple Sign In,我创建了苹果登录,就像 我觉得一切都很好 func authorizationController(controller: ASAuthorizationController, didCompleteWithAuthorization authorization: ASAuthorization) { switch authorization.credential { case let appleIDCredential as ASAuthorizationAppleIDCre
func authorizationController(controller: ASAuthorizationController, didCompleteWithAuthorization authorization: ASAuthorization) {
switch authorization.credential {
case let appleIDCredential as ASAuthorizationAppleIDCredential:
let user = User(credentials: appleIDCredential)
self.saveUserInKeychain(user.id)
let txt = "\(user.id)\n\(user.first_name) \(user.last_name)\n\(user.email)"
let alert = UIAlertController(title: "OK", message: txt, preferredStyle: UIAlertController.Style.alert)
alert.addAction(UIAlertAction(title: "OK", style: UIAlertAction.Style.default, handler: { alertAction in
alert.dismiss(animated: true, completion: nil)
}))
self.present(alert, animated: true, completion: nil)
default:
break
}
}
在我的项目中,我在“签名和功能”中添加了“使用苹果登录”。我在开发人员门户(证书、标识符和配置文件)中选中了“使用苹果登录”
我获得用户凭据。这是工作的一部分
func authorizationController(controller: ASAuthorizationController, didCompleteWithAuthorization authorization: ASAuthorization) {
switch authorization.credential {
case let appleIDCredential as ASAuthorizationAppleIDCredential:
let user = User(credentials: appleIDCredential)
self.saveUserInKeychain(user.id)
let txt = "\(user.id)\n\(user.first_name) \(user.last_name)\n\(user.email)"
let alert = UIAlertController(title: "OK", message: txt, preferredStyle: UIAlertController.Style.alert)
alert.addAction(UIAlertAction(title: "OK", style: UIAlertAction.Style.default, handler: { alertAction in
alert.dismiss(animated: true, completion: nil)
}))
self.present(alert, animated: true, completion: nil)
default:
break
}
}
这里的用户状态是1
但在AppDelegate中,当我再次构建时,我有status.notFound和error:
Error Domain=com.apple.AuthenticationServices.AuthorizationError Code=1000 "(null)"
对于AppDelegate,我使用与Apple相同的代码示例:
if #available(iOS 13.0, *) {
let appleIDProvider = ASAuthorizationAppleIDProvider()
appleIDProvider.getCredentialState(forUserID: KeychainItem.currentUserIdentifier) { (credentialState, error) in
print(error)
switch credentialState {
case .authorized:
DispatchQueue.main.async {
self.window?.rootViewController?.showMainViewControllerAuth()
}
case .revoked, .notFound:
DispatchQueue.main.async {
self.window?.rootViewController?.showMainViewControllerNoAuth()
}
default:
break
}
}
}
这里的用户状态是2
我向TestFlight提交了一个构建,但也出现了错误。notFound(用户状态为2)。
苹果的例子在iOS模拟器中运行良好。但不是我的
我认为问题在这里
Error Domain=com.apple.AuthenticationServices.AuthorizationError Code=1000 "(null)"
代码11.3。目标iOS 11.0
我能忘记什么?我解决了
在didFinishLaunchingWithOptions中的我的AppDelegate中,检查推送通知、fabric和firebase中的注册等。
我不知道为什么,但你需要检查存在苹果认证之前的东西
此部分应该是didFinishLaunchingWithOptions中的第一部分:
if #available(iOS 13.0, *) {
let appleIDProvider = ASAuthorizationAppleIDProvider()
appleIDProvider.getCredentialState(forUserID: KeychainItem.currentUserIdentifier) { (credentialState, error) in
print(error)
switch credentialState {
case .authorized:
DispatchQueue.main.async {
self.window?.rootViewController?.showMainViewControllerAuth()
}
case .revoked, .notFound:
DispatchQueue.main.async {
self.window?.rootViewController?.showMainViewControllerNoAuth()
}
default:
break
}
}
}
检查这个答案谢谢,但我有所有代码1:1