hi I have been using WKWebView embedded in a UIViewRepresentable for displaying inside a SwiftUI View hierarchy, but when I try the same code on 17,5 beta (simulator) the code fails.
In fact, the code runs (no exceptions raised or anything) but the web view does not render. In the console logs I see:
Warning: -[BETextInput attributedMarkedText] is unimplemented
Error launching process, description 'The operation couldn’t be completed. (OSStatus error -10814.)', reason ''
The code I am using to present the view is:
struct MyWebView: UIViewRepresentable {
let content: String
func makeUIView(context: Context) -> WKWebView {
// Javascript that disables pinch-to-zoom by inserting the HTML viewport meta tag into <head>
let source: String = """
var meta = document.createElement('meta');
meta.name = 'viewport';
meta.content = 'width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no';
var style = document.createElement('style');
style.type = 'text/css';
style.innerHTML = '*:focus{outline:none}body{margin:0;padding:0}';
var head = document.getElementsByTagName('head')[0];
head.appendChild(meta);
head.appendChild(style);
"""
let script: WKUserScript = WKUserScript(source: source, injectionTime: .atDocumentEnd, forMainFrameOnly: true)
let userContentController: WKUserContentController = WKUserContentController()
let conf = WKWebViewConfiguration()
conf.userContentController = userContentController
userContentController.addUserScript(script)
let webView = WKWebView(frame: CGRect.zero /*CGRect(x: 0, y: 0, width: 1000, height: 1000)*/, configuration: conf)
webView.isOpaque = false
webView.backgroundColor = UIColor.clear
webView.scrollView.backgroundColor = UIColor.clear
webView.scrollView.isScrollEnabled = false
webView.scrollView.isMultipleTouchEnabled = false
if #available(iOS 16.4, *) {
webView.isInspectable = true
}
return webView
}
func updateUIView(_ webView: WKWebView, context: Context) {
webView.loadHTMLString(content, baseURL: nil)
}
}
This has been working for ages and ages (back to at least ios 15) - something changed. Maybe it is just a problem with the beta 17.5 release?