[ad_1]
I’ve this View with a WebView to show an online web page into an app.
How can I detect the url adjustments of the WebView, and save this url in a UserDefaults variable?
import SwiftUI
import WebKit
struct video: View {
non-public let urlString: String = "https://www.google.com"
var physique: some View {
// Regular WebView
VideoWebView(url: URL(string: urlString)!)
.shadow(coloration: .black.opacity(0.3), radius: 20.0, x: 5, y: 5)
}
}
// WebView Struct
struct VideoWebView: UIViewRepresentable {
var url: URL
func makeUIView(context: Context) -> WKWebView {
return WKWebView()
}
func updateUIView(_ webView: WKWebView, context: Context) {
let request = URLRequest(url: url)
webView.load(request)
}
}
struct video_Previews: PreviewProvider {
static var previews: some View {
video()
}
}
[ad_2]
