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

2024-01-09

替代标题是“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 上无法使用。


如果您遇到这种情况,只需重新启动您的 Mac!然后它就会像预期的那样工作。无需使用包装的 UIKitSignInWithAppleButton。我认为这很可能是 iOS on M1 兼容性问题。

Tried a wrapped UIKit SignInWithAppleButton however the problem persists. I wonder if this is caused by the missing of presentationAnchor which makes it unusable on macOS.

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

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

SwiftUI SignInWithAppleButton onCompletion 永远不会在 M1 Mac 上被调用 的相关文章

随机推荐