A SwiftUI library that opens URLs using in-app Safari View Controller (SFSafariViewController) instead of the external Safari browser.
- Easy integration with SwiftUI
- Optional Reader Mode support
- Replaces default
openURLbehavior - Compatible with iOS 18+
- iOS 18.0+
- Swift 6.3+
- Xcode 16.0+
Add the following to your Package.swift file:
dependencies: [
.package(url: "https://github.com/noppefoxwolf/OpenURLInApp.git", from: "0.1.0")
]Or add it through Xcode:
- File > Add Package Dependencies...
- Enter the repository URL:
https://github.com/noppefoxwolf/OpenURLInApp.git
Since this package targets iOS 18+, you need to build it with an iOS SDK:
Open Package.swift in Xcode and build normally. The scheme will automatically target iOS.
xcodebuild -scheme OpenURLInApp -destination 'platform=iOS Simulator,name=iPhone 16' buildSwift Package Manager's default swift build command targets macOS, so you need to specify an iOS destination:
swift build --destination .build/apple/Products/Debug-iphoneos/Or use Xcode's build system for easier iOS builds.
Apply the onOpenURL(prefersInAppReader:) modifier to your view:
import SwiftUI
import OpenURLInApp
struct ContentView: View {
var body: some View {
Link("Open Link", destination: URL(string: "https://example.com")!)
.onOpenURL(prefersInAppReader: false)
}
}Enable Reader Mode for supported web pages:
Link("Open Article", destination: URL(string: "https://example.com/article")!)
.onOpenURL(prefersInAppReader: true)Access the openURLInApp action directly:
struct ContentView: View {
@Environment(\.openURLInApp) var openURLInApp
var body: some View {
Button("Open URL") {
openURLInApp(URL(string: "https://example.com")!)
}
.onOpenURLInApp()
}
}The library hooks into SwiftUI's openURL environment action and presents an SFSafariViewController instead of opening the URL in the external Safari browser. This provides a seamless in-app browsing experience.
MIT License - See LICENSE file for details