替代标题是“SwiftUI 使用 Apple 按钮登录在 M1 Mac 上不起作用”。
环境 macOS v11.4、Xcode 版本 12.5.1、MacBook Pro(13 英寸、M1、2020)
下列SignInWithAppleButton
代码块在 iOS 模拟器和真实设备上运行良好。但是,在 M1 Mac 上运行时,完成处理程序永远不会被触发。正在阅读文档 https://developer.apple.com/documentation/authenticationservices/signinwithapplebutton它似乎可以在 macOS 11.0+ 上使用。
这是一个已知的 SwiftUI 问题吗?因为当我使用 UIKit 实现时不存在此类问题?
SignInWithAppleButton(
.continue,
onRequest: { request in
request.requestedScopes = [.email]
print(">>> auth on request") // <- Get called on click
},
onCompletion: { result in
print(">>> auth completed") // <- Never get called
switch result {
case let .success(auth):
switch auth.credential {
case let credential as ASAuthorizationAppleIDCredential:
let identityToken = credential.identityToken
if let idToken = identityToken {
Dummy.signUpOrLogInWithApple(idToken: idToken)
}
default:
print(">>> default case")
}
case let .failure(error):
print(">>> Sign in with Apple failed", error.localizedDescription)
}
}
)
Not a solution for this problem but a workaround is to continue using the UIKit version of “Sign in with Apple”,~~ https://github.com/Q42/iOS-Demo-SignInWithApple-SwiftUI/blob/master/iOS-Demo-SignInWithApple-SwiftUI/SignInWithAppleButton.swift https://github.com/Q42/iOS-Demo-SignInWithApple-SwiftUI/blob/master/iOS-Demo-SignInWithApple-SwiftUI/SignInWithAppleButton.swift
我认为这很可能是 SwiftUI 问题。尝试了包装的 UIKit SignInWithAppleButton 但问题仍然存在。我想知道这是否是由于缺少presentationAnchor
这使得它在 macOS 上无法使用。