From 8c8025fb9a1e722913169e65e61bbd86dbcbcf9d Mon Sep 17 00:00:00 2001 From: Dan Cunningham Date: Wed, 11 Sep 2024 13:33:11 -0700 Subject: [PATCH] =?UTF-8?q?Rendering=20of=20the=20openHAB=20ui=20in=20a=20?= =?UTF-8?q?Webview=20on=20an=20iPad=20was=20way=20to=20small.=E2=80=A6=20(?= =?UTF-8?q?#806)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Rendering of the openHAB ui in a Webview on an iPad was way to small. Safari however renders the openHAB UI correctly, this makes our webview behave like Safari. Changing the user agent string is the only way to acheive this. Signed-off-by: Dan Cunningham * Formatting Signed-off-by: Dan Cunningham --------- Signed-off-by: Dan Cunningham --- openHAB/OpenHABWebViewController.swift | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/openHAB/OpenHABWebViewController.swift b/openHAB/OpenHABWebViewController.swift index e0cbb224..6ac6533a 100644 --- a/openHAB/OpenHABWebViewController.swift +++ b/openHAB/OpenHABWebViewController.swift @@ -224,6 +224,7 @@ class OpenHABWebViewController: OpenHABViewController { // adds: window.webkit.messageHandlers.xxxx.postMessage to JS env config.userContentController.add(self, name: "Native") config.userContentController.addUserScript(WKUserScript(source: js, injectionTime: .atDocumentStart, forMainFrameOnly: false)) + let webView = WKWebView(frame: view.bounds, configuration: config) // Alow rotation of webview webView.autoresizingMask = [.flexibleWidth, .flexibleHeight] @@ -233,6 +234,10 @@ class OpenHABWebViewController: OpenHABViewController { // support dark mode and avoid white flashing when loading webView.isOpaque = false webView.backgroundColor = UIColor.clear + if UIDevice.current.userInterfaceIdiom == .pad { + // since ios 13 Safari sets the user agent to desktop mode on iPads so the view renders correctly with larger screens + webView.customUserAgent = "Mozilla/5.0 (iPad; CPU OS 17_5 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.5 Mobile/15E148 Safari/604.1" + } if #available(iOS 16.4, *) { webView.isInspectable = true }