I am working on SwiftUI app where i am navigating to SFSafariviewcontroller (Browser) and once login complete I am getting openurl.
I want close SFSafariviewcontroller automatically once I get openurl.
Thank You for help...below is my work
//how I am calling Safari
.fullScreenCover(isPresented: $isButtonActive, content: {
if let url = loginAction() {
SafariView(url: url)
}
}
//how i am getting openurl
@main
struct MyApplication: App {
var body: some Scene {
WindowGroup {
ContentView()
.onOpenURL { url in
// handle the URL that must be opened
}
}
}
}
my code for safari
import SafariServices
struct Myview: View {
@EnvironmentObject var appConfiguration : AppConfiguration
@State private var isButtonActive = true
@State private var isLoginActive = true
var body: some View {
NavigationView {
Button( buttonTitle: "button" buttonCallback: {
self.isLoginActive = true
}, isActive: $isButtonActive)
}
}
.afklPageView()
.navigationBarTitle("title", displayMode: .inline)
.fullScreenCover(isPresented: $isButtonActive, content: {
if let url = loginAction() {
SafariView(url: url)
}
})
}
}
struct SafariView: UIViewControllerRepresentable {
let url: URL
func makeUIViewController(context: UIViewControllerRepresentableContext<Self>) -> SFSafariViewController {
return SFSafariViewController(url: url)
}
func updateUIViewController(_ uiViewController: SFSafariViewController, context: UIViewControllerRepresentableContext<SafariView>) {
}
}