While having the same issue for a macOS targeted app, I stumbled over this problem as well. Just seconds before I was ready to pull my hair off, I found a mention of entitlements while researching.
So, I went and activated the Outgoing Connections (Client) entitlement – et voilà: it works.
I am quite surprised that this is necessary as the html I want to load is purely local, even in code in my proof of concept right now.
And here's the code:
struct ContentView: View {
var body: some View {
WebViewWrapper(html: "
Hello World!
")}
}
struct WebViewWrapper: NSViewRepresentable {
let html: String
func makeNSView(context: Context) -> WKWebView {
return WKWebView()
}
func updateNSView(_ nsView: WKWebView, context: Context) {
nsView.loadHTMLString(html, baseURL: nil)
}
}