SwiftUI SignInWithAppleButton onCompletion 永远不会在 M1 Mac 上被调用 [英] SwiftUI SignInWithAppleButton onCompletion never get called on M1 Mac

查看:38
本文介绍了SwiftUI SignInWithAppleButton onCompletion 永远不会在 M1 Mac 上被调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

替代标题是SwiftUI Sign in with Apple button 在 M1 Mac 上不起作用".

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

以下 SignInWithAppleButton 代码块在 iOS 模拟器和真实设备上运行良好.但是,在 M1 Mac 上运行时,完成处理程序永远不会被触发.阅读

这是一个已知的 SwiftUI 问题,因为当我使用 UIKit 实现时没有这样的问题吗?

SignInWithAppleButton(.继续,onRequest: { 请求输入request.requestedScopes = [.email]print(">>> auth on request")//<- 在点击时被调用},onCompletion: { 结果在print(">>> auth completed")//<- 永远不会被调用切换结果{case let .success(auth):切换 auth.credential {case let credential as ASAuthorizationAppleIDCredential:让 identityToken = credential.identityToken如果让 idToken = identityToken {Dummy.signUpOrLogInWithApple(idToken: idToken)}默认:打印(>>>默认情况")}case let .failure(error):print(">>> Sign in with Apple failed", error.localizedDescription)}})

不是这个问题的解决方案,而是继续使用 UIKit 版本的Sign in with Apple",~~

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

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

The alternative title is "SwiftUI Sign in with Apple button does not work on M1 Mac".

Environment macOS v11.4, Xcode Version 12.5.1, MacBook Pro (13-inch, M1, 2020)

The following SignInWithAppleButton code block works fine on iOS simulators and real devices. However, the completion handler never gets triggered when running it on an M1 Mac. Reading the documentation and it seems to be available on macOS 11.0+.

Is this a known SwiftUI issue because there is no such issue when I am using an UIKit implementation?

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

I think it is most likely a SwiftUI issue. 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.

解决方案

IF THIS HAPPENED TO YOU JUST RESTART YOUR MAC!!! and then it would work just as expected. No need to use a wrapped UIKit SignInWithAppleButton. I think it is most likely an iOS on M1 compatibility issue.

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

这篇关于SwiftUI SignInWithAppleButton onCompletion 永远不会在 M1 Mac 上被调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆