swift – WKWebView iOS 16 Internet Share API on file: protocol

[ad_1]

I’m making an attempt to make use of navigator.share in a file operating in WKWebView on iOS 16. The file is loaded into the online view utilizing a file: protocol path like so:

uiView.loadFileURL(Bundle.fundamental.url(forResource: "index", withExtension: "html", subdirectory: "internet")!, allowingReadAccessTo: Bundle.fundamental.bundleURL)

I’ve this setting on:

configuration.preferences.setValue(true, forKey: "allowFileAccessFromFileURLs")

So I’m able to load file: protocol information into the online view, however I do not appear to have the ability to use the Internet Share API. I get this error:

NotAllowedError: The request isn’t allowed by the person agent or the platform within the present context, presumably as a result of the person denied permission.

Nevertheless, once I level the online view at this HTTPS URL, it really works:

https://mdn.github.io/dom-examples/web-share

This leads me to consider the Internet Share API isn’t working as a result of the HTML file loaded over the file: protocol isn’t seen as safe and thus the JavaScript runtime do not deal with the code on it as if it was operating in a safe context.

Because of this, I consider the entry to the navigator.share API is forbidden.

Is there a approach to configure WKWebView to permit entry to safe context JS/DOM/internet APIs with out utilizing a customized scheme (and including an additional layer atop simply loading my file from the bundle)?

[ad_2]

Leave a Reply

Your email address will not be published. Required fields are marked *