I wanted to show how easy it is to use the Store Locator Widget, or any other webpage, from within a Swift app. It’s only a few lines of code to get the SLW up and running on iOS.
In the example below the app is loading the Bose Store Locator Widget from the documentation.
import SwiftUI
import WebKit
struct WebView: UIViewRepresentable{
let url: URL?
private let webView = WKWebView()
func makeUIView(context: Context) -> some UIView {
return webView
}
func updateUIView(_ uiView: UIViewType, context: Context) {
guard let url = url else {
return
}
webView.load(.init(url: url))
}
}
struct ContentView: View {
var body: some View {
//Bose
WebView(url: URL(string: "https://3icrvl.csb.app/"))
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}