Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ios): Add setServerBasePath(_:) to CAPBridgeProtocol (#5860) #5892

Merged
merged 2 commits into from
Aug 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ios/Capacitor/Capacitor/CAPBridgeProtocol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ import WebKit
// MARK: - Paths, Files, Assets
func localURL(fromWebURL webURL: URL?) -> URL?
func portablePath(fromLocalURL localURL: URL?) -> URL?
func setServerBasePath(_ path: String)

// MARK: - View Presentation
func showAlertWith(title: String, message: String, buttonTitle: String)
Expand Down
14 changes: 4 additions & 10 deletions ios/Capacitor/Capacitor/CAPBridgeViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -258,16 +258,10 @@ extension CAPBridgeViewController {
}

@objc public func setServerBasePath(path: String) {
let url = URL(fileURLWithPath: path, isDirectory: true)
guard let capBridge = capacitorBridge, FileManager.default.fileExists(atPath: url.path) else {
return
}
capBridge.config = capBridge.config.updatingAppLocation(url)
capBridge.webViewAssetHandler.setAssetPath(url.path)
if let url = capacitorBridge?.config.serverURL {
DispatchQueue.main.async { [weak self] in
_ = self?.webView?.load(URLRequest(url: url))
}
guard let capBridge = capacitorBridge else { return }
capBridge.setServerBasePath(path)
DispatchQueue.main.async { [weak self] in
_ = self?.webView?.load(URLRequest(url: capBridge.config.serverURL))
}
}
}
Expand Down
7 changes: 7 additions & 0 deletions ios/Capacitor/Capacitor/CapacitorBridge.swift
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,13 @@ internal class CapacitorBridge: NSObject, CAPBridgeProtocol {
statusBarAnimation = animation
}

public func setServerBasePath(_ path: String) {
let url = URL(fileURLWithPath: path, isDirectory: true)
guard FileManager.default.fileExists(atPath: url.path) else { return }
config = config.updatingAppLocation(url)
webViewAssetHandler.setAssetPath(url.path)
}

// MARK: - Static Methods

/**
Expand Down