Skip to content

Commit

Permalink
fix(ios): print warning without exiting if index not found
Browse files Browse the repository at this point in the history
  • Loading branch information
mlynch committed Jun 5, 2019
1 parent d467c9f commit 9778c4c
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions ios/Capacitor/Capacitor/CAPBridgeViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,17 @@ public class CAPBridgeViewController: UIViewController, CAPBridgeDelegate, WKScr
private var handler: CAPAssetHandler?

override public func loadView() {
guard let startPath = self.getStartPath() else {
return
}

setStatusBarDefaults()
setScreenOrientationDefaults()

HTTPCookieStorage.shared.cookieAcceptPolicy = HTTPCookie.AcceptPolicy.always
let webViewConfiguration = WKWebViewConfiguration()
self.handler = CAPAssetHandler()
self.handler!.setAssetPath(self.getStartPath())
self.handler!.setAssetPath(startPath)
webViewConfiguration.setURLSchemeHandler(self.handler, forURLScheme: CAPBridge.CAP_SCHEME)

let o = WKUserContentController()
Expand Down Expand Up @@ -67,10 +71,11 @@ public class CAPBridgeViewController: UIViewController, CAPBridgeDelegate, WKScr
}
}

private func getStartPath() -> String {
private func getStartPath() -> String? {
let fullStartPath = URL(fileURLWithPath: "public").appendingPathComponent(startDir)
guard var startPath = Bundle.main.path(forResource: fullStartPath.relativePath, ofType: nil) else {
fatalLoadError()
printLoadError()
return nil
}

let defaults = UserDefaults.standard
Expand All @@ -91,13 +96,17 @@ public class CAPBridgeViewController: UIViewController, CAPBridgeDelegate, WKScr
loadWebView()
}

func fatalLoadError() -> Never {
func printLoadError() {
let fullStartPath = URL(fileURLWithPath: "public").appendingPathComponent(startDir)

print("⚡️ FATAL ERROR: Unable to load \(fullStartPath.relativePath)/index.html")
print("⚡️ ERROR: Unable to load \(fullStartPath.relativePath)/index.html")
print("⚡️ This file is the root of your web app and must exist before")
print("⚡️ Capacitor can run. Ensure you've run capacitor copy at least")
print("⚡️ or, if embedding, that this directory exists as a resource directory.")
}

func fatalLoadError() -> Never {
printLoadError()
exit(1)
}

Expand Down

0 comments on commit 9778c4c

Please sign in to comment.