meismyles / SwiftWebVC

A drop-in inline browser for your Swift iOS app.
MIT License
329 stars 117 forks source link

Doesn't display local files properly #43

Open mattwritescode opened 6 years ago

mattwritescode commented 6 years ago

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)
        }
}
peterdk commented 5 years ago

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.