Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/divadretlaw/safariservicesui
🧠SafariServices for SwiftUI
https://github.com/divadretlaw/safariservicesui
ios safari swift swiftui visionos
Last synced: about 2 months ago
JSON representation
🧠SafariServices for SwiftUI
- Host: GitHub
- URL: https://github.com/divadretlaw/safariservicesui
- Owner: divadretlaw
- License: apache-2.0
- Created: 2024-03-09T22:17:54.000Z (10 months ago)
- Default Branch: main
- Last Pushed: 2024-09-04T04:04:56.000Z (4 months ago)
- Last Synced: 2024-10-24T04:26:22.362Z (2 months ago)
- Topics: ios, safari, swift, swiftui, visionos
- Language: Swift
- Homepage:
- Size: 45.9 KB
- Stars: 6
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# SafariServicesUI
🧠SafariServices for SwiftUI
Enable web views and services in your app.
## Safari
### `OpenURLAction`
#### `safari(_:)`
Use `SFSafariViewController` as an action in `openURL`
```swift
@main
struct MyApp: App {
var body: some Scene {
WindowGroup {
ContentView()
.environment(\.openURL, OpenURLAction { url in
.safari(url)
})
}
}
}
```You can also provide an optional configuration
```swift
.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.
```swift
@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`.
```swift
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
```swift
.safari(url: $showURL) { configuration in
// Apply your configuration to `configuration`
}
```## Authentication Services
Present a authentication session via
```swift
.authenticationSession(isPresented: $isPresented, configuration: AuthenticationSessionConfiguration) { result in
// Handle result
}
```or use the predefined `Button`
```swift
AuthenticationSessionButton(configuration: AuthenticationSessionConfiguration) {
Text("Authenticate")
} onCompletion: { result in
// Handle result
}
```## License
See [LICENSE](LICENSE)