From 9c25aad0ca8f97416753e7589a92efa401ad75bc Mon Sep 17 00:00:00 2001 From: Steven Sherry Date: Tue, 12 Jul 2022 09:32:01 -0500 Subject: [PATCH] feat(ios): Add `setServerBasePath(path:)` to CAPWebView (#5742) (#5748) --- ios/Capacitor/Capacitor/CAPWebView.swift | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/ios/Capacitor/Capacitor/CAPWebView.swift b/ios/Capacitor/Capacitor/CAPWebView.swift index f7d3784f62..793fc25a4a 100644 --- a/ios/Capacitor/Capacitor/CAPWebView.swift +++ b/ios/Capacitor/Capacitor/CAPWebView.swift @@ -104,6 +104,19 @@ open class CAPWebView: UIView { open func loadInitialContext(_ userContentController: WKUserContentController) { CAPLog.print("in loadInitialContext base") } + + public func setServerBasePath(path: String) { + let url = URL(fileURLWithPath: path, isDirectory: true) + guard FileManager.default.fileExists(atPath: url.path) else { return } + + capacitorBridge.config = capacitorBridge.config.updatingAppLocation(url) + capacitorBridge.webViewAssetHandler.setAssetPath(url.path) + + DispatchQueue.main.async { [weak self] in + guard let self = self else { return } + _ = self.webView.load(URLRequest(url: self.capacitorBridge.config.serverURL)) + } + } } extension CAPWebView {