SwiftUI SignInWithAppleButton onCompletion 永远不会在 M1 上被调用 Mac

SwiftUI SignInWithAppleButton onCompletion never get called on M1 Mac

替代标题是“SwiftUI 使用 Apple 按钮登录在 M1 上不起作用 Mac”。

环境 macOS v11.4,Xcode 版本 12.5.1,MacBook Pro(13 英寸,M1,2020)

以下 SignInWithAppleButton 代码块在 iOS 模拟器和真实设备上运行良好。但是,当 运行 它在 M1 Mac 上时,完成处理程序永远不会被触发。阅读 documentation,它似乎在 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)
        }
    }
)

不是这个问题的解决方案,解决办法是继续使用UIKit版本的“Sign in with Apple”,~~ https://github.com/Q42/iOS-Demo-SignInWithApple-SwiftUI/blob/master/iOS-Demo-SignInWithApple-SwiftUI/SignInWithAppleButton.swift

我认为这很可能是 SwiftUI 问题。尝试了包装的 UIKit SignInWithAppleButton 但是问题仍然存在。我想知道这是不是因为 presentationAnchor 的缺失导致它在 macOS 上无法使用。

如果您遇到这种情况,只需重新启动您的 MAC!!!,然后它就会按预期工作。无需使用包装的 UIKit SignInWithAppleButton。我认为这很可能是 iOS 关于 M1 兼容性问题。

尝试了包装的 UIKit SignInWithAppleButton,但问题仍然存在。我想知道这是否是由于缺少 presentationAnchor 导致它在 macOS 上无法使用造成的。

不是这个问题的解决方案,但解决方法是继续使用UIKit版本的“使用Apple登录”,~~ https://github.com/Q42/iOS-Demo-SignInWithApple-SwiftUI/blob/master/iOS-Demo-SignInWithApple-SwiftUI/SignInWithAppleButton.swift