SwiftUI macOS SignInWithAppleButton in

In SwiftUI I got error when I use SignInWithAppleButton in SplitReplacementHostingController I got crash

Code Block language
Fatal error: Attempting to present ASAuthorizationController from a SwiftUI view not in a heirarchy. This should not be possible, please file feedback.: file _AuthenticationServices_SwiftUI/SignInWithAppleButton.swift, line 300
Fatal error: Attempting to present ASAuthorizationController from a SwiftUI view not in a heirarchy. This should not be possible, please file feedback.: file _AuthenticationServices_SwiftUI/SignInWithAppleButton.swift, line 300

When I place the same button to first screen in the app it works

Mainly it is because I have Sidebar and NavigationView which is preferred for the macOS so when I have the two column placeholder there as the button it works but when I navigate via NavigationLink it stop working

I used Xcode 12.2 beta 3 (12B5035g) Big Sur 20A5395g


Hit the same issue

Fatal error: Attempting to present ASAuthorizationController from a SwiftUI view not in a heirarchy. This should not be possible, please file feedback.: file AuthenticationServicesSwiftUI/SignInWithAppleButton.swift, line 300
same...

Fatal error: Attempting to present ASAuthorizationController from a SwiftUI view not in a heirarchy. This should not be possible, please file feedback.: file AuthenticationServicesSwiftUI/SignInWithAppleButton.swift, line 300
Same issue here
Same issue here. A partial solution is to add the sign in with apple button to a navigation view.

But if you log out and pop back to the login screen, it seems to happen again.
Same issue, any solution right now?
Same issue here. Adding button to navigation bar didn't work for me
Filled a feedback to Apple - FB9016841

so was there any Feedback on this?

I got to meet with some Apple Engineers at WWDC22. They suggested to create a UIViewRepresentable that is a wrapper around the ASAuthorizationAppleIDButton.

Then hook it up to a ASAuthorizationController and set the presentationContextProvider.

    let request = ASAuthorizationAppleIDProvider().createRequest()
    request.requestedScopes = [.fullName, .email]
    let controller = ASAuthorizationController(authorizationRequests: [request])
    controller.delegate = self
    controller.presentationContextProvider = self
    controller.performRequests()

And then on the presentationContextProvider protocol implementation provide the proper key window to use for popup presentation.

 public func presentationAnchor(for controller: ASAuthorizationController) -> ASPresentationAnchor {
    let keyWindow = (UIApplication.shared.connectedScenes.first?.delegate as? SceneDelegate)?.window
    return keyWindow ?? ASPresentationAnchor()
  }

That's what I tried. I used this example as my template for creating the SwiftUI wrapper button and a coordinator. SiwaButton.swift

SwiftUI macOS SignInWithAppleButton in
 
 
Q