我已在项目目标中启用 SIWA 的权利。相同的步骤在 iOS 模拟器中运行良好。
我在 tvOS 模拟器上尝试使用 Apple (SIWA) 登录时遇到以下问题。
重现问题的步骤:
- 在点击自定义按钮请求 SIWA 时,全屏显示 Apple id 密码(未提供选择电子邮件中继的选项)(最后附上屏幕截图以供参考)
- 输入正确的密码后,我会在错误委托中收到回调。
错误委托中的错误:
错误错误域=com.apple.AuthenticationServices.AuthorizationError代码=1000“(空)”
下面是整个过程的代码片段。
我已经按照 iOS 版 SIWA 官方文档完成了所需的所有步骤。
仅供参考:相同的代码适用于我的 iOS,但不适用于 tvOS。我在开发过程中在 iPhone 模拟器中测试了 SIWA,现在在 tvOS 上尝试相同的操作,但它不起作用。
下面是我的代码。
这里,在ViewController的viewDidLoad上调用函数setup()
private func setup() {
if #available(tvOS 13.0, *) {
let appleIDProvider = ASAuthorizationAppleIDProvider()
appleIDProvider.getCredentialState(forUserID: "myapp.identifiers.currentUserIdentifier") { (credential, error) in
switch credential {
case .authorized:
print("authorized for sign in")
break
case .notFound, .revoked, .transferred:
print("ready to logout")
break
default:
print("Apple sign in credential state unidentified")
}
}
}
}
在自定义 SIWA 按钮的操作方法内,我的代码如下所示
if #available(tvOS 13.0, *) {
let appleIDProvider = ASAuthorizationAppleIDProvider()
let request = appleIDProvider.createRequest()
request.requestedScopes = [.fullName, .email]
let authorizationController = ASAuthorizationController(authorizationRequests: [request])
authorizationController.delegate = self
authorizationController.presentationContextProvider = self
authorizationController.performRequests()
}
呈现锚点在 ViewController 的扩展中设置
extension ENWelcomeScreenViewController: ASAuthorizationControllerPresentationContextProviding {
@available(tvOS 13.0, *)
func presentationAnchor(for controller: ASAuthorizationController) -> ASPresentationAnchor {
return self.view.window!
}
}
最后是错误委托,我在其中接收回调。
/// - Tag: did_complete_error
@available(tvOS 13.0, *)
func authorizationController(controller: ASAuthorizationController, didCompleteWithError error: Error) {
print("error \(error)")
}
以下是用户点击 SIWA 按钮时的外观。
任何线索都将受到高度赞赏。