🧠SafariServices for SwiftUI
Enable web views and services in your app.
Use SFSafariViewController
as an action in openURL
@main
struct MyApp: App {
var body: some Scene {
WindowGroup {
ContentView()
.environment(\.openURL, OpenURLAction { url in
.safari(url)
})
}
}
}
You can also provide an optional configuration
.environment(\.openURL, OpenURLAction { url in
.safari(url) { configuration in
// Apply your configuration to `configuration`
}
})
Use SFSafariViewController
as an action in openURL
on a specific window scene.
@main
struct MyApp: App {
var body: some Scene {
WindowGroup {
WindowSceneReader { windowScene in
ContentView()
.environment(\.openURL, OpenURLAction { url in
.safariWindow(url, in: windowScene)
})
}
}
}
}
Display an URL
in SFSafariViewController
.
struct ContentView: View {
@State private var showURL: URL?
var body: some View {
Button("Show URL) {
showURL = URL(...)
}
.safari(url: $showURL)
}
}
You can also provide an optional configuration
.safari(url: $showURL) { configuration in
// Apply your configuration to `configuration`
}
Present a authentication session via
.authenticationSession(isPresented: $isPresented, configuration: AuthenticationSessionConfiguration) { result in
// Handle result
}
or use the predefined Button
AuthenticationSessionButton(configuration: AuthenticationSessionConfiguration) {
Text("Authenticate")
} onCompletion: { result in
// Handle result
}
See LICENSE