Skip to content

🧭 SafariServices for SwiftUI

License

Notifications You must be signed in to change notification settings

divadretlaw/SafariServicesUI

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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