Open local PDF files with tabs

Hi,

I am trying to open a local pdf file:

I have an url like this:

content://forge-content/?uri=%2FUsers%2Ffribu%2FLibrary%2FDeveloper%2FCoreSimulator%2FDevices%2F03FBB101-F71F-4B69-B5A8-23A21897A5E9%2Fdata%2FContainers%2FData%2FApplication%2F0DC38568-946C-4D47-A904-6D6A39742AB6%2FLibrary%2FApplication%20Support%2FForge%2F0A07320A-A182-46AA-9A56-759693B0F2F819b59a99da666ac9ecaae48c94918a3d.pdf

I have also tried to replace urls items and open url like this:

/Users/fribu/Library/Developer/CoreSimulator/Devices/03FBB101-F71F-4B69-B5A8-23A21897A5E9/data/Containers/Data/Application/0DC38568-946C-4D47-A904-6D6A39742AB6/Library/Application Support/Forge/0A07320A-A182-46AA-9A56-759693B0F2F819b59a99da666ac9ecaae48c94918a3d.pdf

The file is present.

The code:

forge.tabs.openWithOptions({
        url,
        title,
        buttonText: this.getIntlMessage('close')
    });

I am using the latest forge version 2.8.3 and tabs 3.2
Tested with iPhone 8 Simulator (ios 13.2) and also on devices.

Any idea?

The screen stays blank…

2 Likes

I’m assuming you’re getting your URL via forge.file.URL - the problem is that this API was designed for embedding local image resources into the main webview rather than providing a url for the forge tabs module.

To get a valid file:/// url that you can reference with the tabs module try something like:

forge.tools.getURL("path/to/local/file.pdf", function (url) {
    forge.tabs.openWithOptions({
        url: url
    }, function () { 
        ...
    });
});

Thanks. We tried to use forge.tools.getURL instead of forge.file.URL, but unfortunately when trying to open the file:/// resource, we get the following error: Not allowed to load local resource. This makes sense, because the App uses https://localhost:41801 (httpd module).
Is it possible to provide a URL for local files via httpd, so it’s the same origin?

Weird, it works for me.

That said, you could try something like: https://localhost:41801/src/path_to_file.pdf

The file was stored by using forge.file.saveURL. When I use forge.tools.getURL on the file object I get an absolute file path, I don’t think it works on https://localhost:41801/src/. Did you test the file:/// resource on iOS 13?

That would have been helpful information :slight_smile:

Apple put some major restrictions on WKWebView file access in the last iOS version or two. tl;dr is that files downloaded from the internet and stored in your app’s local sandbox are not currently supported for WKWebView and tabs module.

You can only view remote pdf’s by directly passing in the pdf’s remote URL.

Will see what we can do to expose the rest of the sandbox filesystem to apps via httpd for the next platform release!

OK, thank you. A solution via httpd would be nice.

I’ve pushed a couple of updates, can you please try this against:

Forge platform version: v2.8.4
Tabs module version: 3.4

This is my test case:

var pdf_url = "https://ops.trigger.io/75d92dce/tests/test.pdf";
forge.file.saveURL(pdf_url, function (file) {
    forge.tools.getURL(file, function (url) {
        forge.tabs.openWithOptions({
            url: url,
            title: "My title",
            buttonText: "Done"
        }, function (data) {
            // ...
        });
    });
});

With the updates the PDF downloads of local files are working again as expected. Thank you!!!

1 Like

OK, there is one more issue :slight_smile:
We have an App crash when opening a PDF on iOS 12.4 in the Tabs module now.
Can you reproduce this issue? We only experience it on a real device, not in the simulator.Forge-2019-11-19-174747.log (3.4 KB)

Joy :slight_smile:

I’ve pushed an updated version of the tabs module to 3.4.1 - can you please give it a shot?

Yes, it works! Thanks again for the quick fix.

1 Like