Skip to content

Commit 76f28e7

Browse files
authored
feat(ios): Add setServerBasePath(_:) to CAPBridgeProtocol (#5860)
1 parent c700256 commit 76f28e7

File tree

3 files changed

+12
-10
lines changed

3 files changed

+12
-10
lines changed

ios/Capacitor/Capacitor/CAPBridgeProtocol.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ import WebKit
7070
// MARK: - Paths, Files, Assets
7171
func localURL(fromWebURL webURL: URL?) -> URL?
7272
func portablePath(fromLocalURL localURL: URL?) -> URL?
73+
func setServerBasePath(_ path: String)
7374

7475
// MARK: - View Presentation
7576
func showAlertWith(title: String, message: String, buttonTitle: String)

ios/Capacitor/Capacitor/CAPBridgeViewController.swift

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -263,16 +263,10 @@ extension CAPBridgeViewController {
263263
}
264264

265265
@objc public func setServerBasePath(path: String) {
266-
let url = URL(fileURLWithPath: path, isDirectory: true)
267-
guard let capBridge = capacitorBridge, FileManager.default.fileExists(atPath: url.path) else {
268-
return
269-
}
270-
capBridge.config = capBridge.config.updatingAppLocation(url)
271-
capBridge.webViewAssetHandler.setAssetPath(url.path)
272-
if let url = capacitorBridge?.config.serverURL {
273-
DispatchQueue.main.async { [weak self] in
274-
_ = self?.webView?.load(URLRequest(url: url))
275-
}
266+
guard let capBridge = capacitorBridge else { return }
267+
capBridge.setServerBasePath(path)
268+
DispatchQueue.main.async { [weak self] in
269+
_ = self?.webView?.load(URLRequest(url: capBridge.config.serverURL))
276270
}
277271
}
278272
}

ios/Capacitor/Capacitor/CapacitorBridge.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,13 @@ internal class CapacitorBridge: NSObject, CAPBridgeProtocol {
156156
statusBarAnimation = animation
157157
}
158158

159+
public func setServerBasePath(_ path: String) {
160+
let url = URL(fileURLWithPath: path, isDirectory: true)
161+
guard FileManager.default.fileExists(atPath: url.path) else { return }
162+
config = config.updatingAppLocation(url)
163+
webViewAssetHandler.setAssetPath(url.path)
164+
}
165+
159166
// MARK: - Static Methods
160167

161168
/**

0 commit comments

Comments
 (0)