SwiftWebVC icon indicating copy to clipboard operation
SwiftWebVC copied to clipboard

Doesn't display local files properly

Open mattwritescode opened this issue 6 years ago • 1 comments

When trying to display a local file like this url: "file:///var/mobile/Containers/Data/Application/blahblahblah/downloads/15212173031370-A8AB82E7-A719-4148-89CE-D5CE9FD468C6.jpg" it doesn't display anything. This is related to an old WKWebView bug that has since been fixed back in iOS 9. It requires that we load the url with
webView.loadFileURL(url, allowingReadAccessTo: url) instead of webView.load(request)

I've managed to find a spot to drop that in that works, but is a little ugly and probably doesn't match the organization of the existing code very well.

If you drop the following code in right here it fixes things.

func loadRequest(_ request: URLRequest) {
        if let url = request.url,
            url.absoluteString.contains("file:"),
            #available(iOS 9.0, *) {
                webView.loadFileURL(url, allowingReadAccessTo: url)
        } else {
            webView.load(request)
        }
}

mattwritescode avatar Mar 16 '18 20:03 mattwritescode

We are running into the same issue and have spent hours on getting to understand why it did not load. I see the fix has been commited, so please release a new version to Cocoapods.

peterdk avatar Nov 19 '19 12:11 peterdk