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
Topic:
UI Frameworks
SubTopic:
SwiftUI
Tags: