2

TL;DR - I want to download a .csv and other files from a link, and present a UIActivityViewController.

I'm working in an app with lots of WKWebViews. In one of the delegate methods, decidePolicyForNavigationAction:, the available URL is a URL compatible with URLRequests, and I can download just fine from it. (navigationAction.request.url)

In another delegate method decidePolicyForNavigationResponse: the response's url (navigationResponse.response.url) identifies as part of Apple's QuickLook framework scheme, and contains this: x-apple-ql-magic. I was trying to use a QLPreviewController, but couldn't populate the dataSource with a remote file I wanted to download.

My goal is: When a link points to a downloadable file, like a .csv or PDF, give a user the option to share this file via UIActivityViewController.

How can I download remote files from this scheme: x-apple-ql-magic?

ArielSD
  • 829
  • 10
  • 27

1 Answers1

3

You can’t. When WKWebView previews a file such as CSV, it is internally converted to HTML by Quick Look to be rendered by WebKit. The x-apple URL is the URL of the converted content. It should not be exposed to you, you should be seeing the original URL instead, please file a bug.

Why do you want to use the response delegate in the first place instead of the delegate at link tap time?

Thomas Deniau
  • 2,488
  • 1
  • 15
  • 15
  • Because the x-apple url has a .csv extension, which is easier to check, and there are some QuickLook methods like `canPreview` that I was trying to use in the `navigationResponse` delegate method. Great answer, though, thank you! – ArielSD Oct 03 '17 at 15:10
  • Is there any way to know the actual MimeType instead of `text/html` for csv file? – Mrug May 25 '20 at 19:27
  • I’m not sure I understand the question, but in any case you should not rely on these x-apple URLs. These are implementation details and can change. They are not API. – Thomas Deniau May 27 '20 at 11:24