SafariServicesUI

main

🧭 SafariServices for SwiftUI
divadretlaw/SafariServicesUI

SafariServicesUI

🧭 SafariServices for SwiftUI

Enable web views and services in your app.

Safari

OpenURLAction

safari(_:)

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`
    }
})

safariWindow(_:in:)

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)
                })
            }
        }
    }
}

safari(url:)

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`
}

Authentication Services

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
}

License

See LICENSE

Description

  • Swift Tools 5.9.0
View More Packages from this Author

Dependencies

Last updated: Mon Apr 15 2024 00:15:51 GMT-0900 (Hawaii-Aleutian Daylight Time)