From 9778c4c5fa9ed481f4039dcec65477852a541226 Mon Sep 17 00:00:00 2001 From: Max Lynch Date: Wed, 5 Jun 2019 13:50:24 -0500 Subject: [PATCH] fix(ios): print warning without exiting if index not found --- .../Capacitor/CAPBridgeViewController.swift | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/ios/Capacitor/Capacitor/CAPBridgeViewController.swift b/ios/Capacitor/Capacitor/CAPBridgeViewController.swift index 8917a41ed..fb1733600 100644 --- a/ios/Capacitor/Capacitor/CAPBridgeViewController.swift +++ b/ios/Capacitor/Capacitor/CAPBridgeViewController.swift @@ -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() @@ -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 @@ -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) }