Member-only story
Mastering OpenURL & Deep Links in SwiftUI & iOS
OpenURL is a powerful mechanism in SwiftUI that allows our app to handle both internal and external links. In this comprehensive guide, we will walk through the basics to advanced usage of OpenURL in SwiftUI.
Read for free at:
Let’s start with basics of OpenURL.
The openURL
allows our apps to handle URLs in a consistent way across different views and components. We can get started with openURL
modifier.
struct OpenURLExample: View {
@Environment(\.openURL) private var openURL
var body: some View {
Button("Visit DevTechie") {
openURL(URL(string: "https://www.devtechie.com")!)
}
}
}
Let’s create a custom view to handle external links. We will create a new view named “ExternalLink.” This view will require a URL and a label as initialization parameters. Once we have these parameters, we can…