How to implement a WKWebView in SwiftUI which is not asking two times for the permission of the location?
I use Xcode 14.0.1 and Swift Version 5.7. In Xcode under Info in Custom iOS Target Properties, I added the Key Privacy - Location When In Use Usage Description which is responsible for the first permission prompt. I just want to show this prompt (as it works when I use Cordova).
The following code
import SwiftUI
import WebKit
struct ContentView: View {
var body: some View {
WebView()
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
struct WebView: UIViewRepresentable {
func makeUIView(context: Context) -> WKWebView {
let webView = WKWebView()
return webView
}
func updateUIView(_ webView: WKWebView, context: Context) {
webView.load(URLRequest(url: URL(string: "https://www.openstreetmap.org")!))
}
}
shows the following two permission prompts
First permission prompt (which is correct)
Second permission prompt (which should be avoided)
I also tried the solution from stackoverflow which did not work.