Skip to content

Commit

Permalink
Add redirect fix for local file path URLs
Browse files Browse the repository at this point in the history
  • Loading branch information
tzachari committed Sep 6, 2019
1 parent 209cf9c commit 507ea40
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions XRViewer/WebController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,14 @@ class WebController: NSObject, WKUIDelegate, WKNavigationDelegate, WKScriptMessa
}

func webView(_ webView: WKWebView, didFailProvisionalNavigation navigation: WKNavigation!, withError error: Error) {
appDelegate().logger.error("Web Error - \(error)")
if error._domain == "WebKitErrorDomain", let info = error._userInfo as? [String:Any], let url = info[NSURLErrorFailingURLStringErrorKey],
let urlString = url as? String, urlString.hasPrefix("file:"), urlString.hasSuffix("/") {
// Redirect fix to get default HTML page for file path URLs
// TODO: Verify this is needed - thought it worked w/o this before; may have broke something elsewhere?
loadURL(urlString + "index.html")
} else {
appDelegate().logger.error("Web Error (didFailProvisional) - \(error)")
}

if self.webView?.observationInfo != nil {
self.webView?.removeObserver(self, forKeyPath: "estimatedProgress")
Expand All @@ -484,7 +491,7 @@ class WebController: NSObject, WKUIDelegate, WKNavigationDelegate, WKScriptMessa
}

func webView(_ webView: WKWebView, didFail navigation: WKNavigation!, withError error: Error) {
appDelegate().logger.error("Web Error - \(error)")
appDelegate().logger.error("Web Error (didFail) - \(error)")

if self.webView?.observationInfo != nil {
self.webView?.removeObserver(self as NSObject, forKeyPath: "estimatedProgress")
Expand Down

0 comments on commit 507ea40

Please sign in to comment.