I'm developing a Web app using a WKWebView. The problem I'm facing right now is the following:
I'm using webView(_ webView: WKWebView, decidePolicyFor navigationResponse: WKNavigationResponse, decisionHandler: @escaping (WKNavigationResponsePolicy) -> Void)
to determine whether the user is trying to access an attached file like a .pdf, .mov, .docx or .pages and allow or cancel the navigation using the decisionHandler
.
However when I try to access the navigationResponse
's response
property via
if let response = navigationResponse.response as? HTTPURLResponse
the optional check fails for certain file types like .docx, .pages, .rtf. For other types like .mov everthing works as expected.
Inspecting navigationResponse.response.url
for the critical navigations towards files like .rtf I find the following:
x-apple-ql-id://BB110CD9-7330-4A39-82E4-6E550E9AC4EB/x-apple-ql-magic/ein%20text.rtf
I have found out so far that this url scheme belongs to Apple's Quicklook framework which is used to display certain file contents within WKWebView to the user. However this scheme is only used internally and should not appear there.
After the optional check of navigationResponse.response
and casting it to HTTPURLResponse
fails, I try to cancel the navigation calling decisionHandler(.cancel)
. The result is my webview showing a blanc page and none of the WKWebViews error functions, nor the
didFinish` method being called.
If I try to schedule any request after this happened via webView.load(someRequest)
webView(_ webView: WKWebView, didFailProvisionalNavigation navigation: WKNavigation!, withError error: Error)
gets called with error
being Error Domain=WebKitErrorDomain Code=102
aka. "Frame load interrupted".
I have no idea what causes WKWebView to show such strange behavior.
The OS is iOS 11.4.
Does anyone have an idea what might be the cause or is anyone able to give a hint where to investigate further?
Thank you very much.