file protocol not working for webview (except bundled files)

Right now (Fuse 1.8.1) the file protocol is only working for bundled files.
If you have the following use case (like I):

  • download a file from web
  • save it to apppath/documents
  • display the file via WebView

nothing is displayed (except fuse preview, ios simulator)!

That’s because Fuse WebView implements loadRequest to show the url. After iOS 9.0 (or 8.0?) it’s necessary to implement loadFileURL if the file protocol is used. This call is combined with allowingReadAccessToURL, which is the root of the WKWebView instance that is allowed to display.

I modified the WKWebViewHelpers::LoadURL from

        id nsurl = [NSURL URLWithString:url];
        id request = [[NSURLRequest alloc] initWithURL:nsurl];
        [wv loadRequest:request];

to

        NSURL *documentsURL = [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] objectAtIndex:0];

        id nsurl = [NSURL URLWithString:url];
        id request = [[NSURLRequest alloc] initWithURL:nsurl];
        [wv loadRequest:request];
        if ([url hasPrefix:@"file://"]) {
            [wv loadFileURL:nsurl allowingReadAccessToURL:documentsURL];
        } else {
            [wv loadRequest:request];
        }

This modification let us load files from the apppath/documents folder.

To be flexible the best way would be to implement loadFileURL.

I really made up my mind where to put this. I think it’s more a bug than a feature request, 'cause the file protocol works somehow but not complete… And I think this use case is a common scenario?

Hi,

the WebView implementation lives here. You’re welcome to make the necessary changes and submit a pull request.