Friday, May 16, 2025
HomeiOS Developmentswift - WKWebView iOS 16 Internet Share API on file: protocol

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 net view utilizing a file: protocol path like so:

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

I’ve this setting on:

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

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

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

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

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

This leads me to imagine the Internet Share API shouldn’t be working as a result of the HTML file loaded over the file: protocol shouldn’t be 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 imagine the entry to the navigator.share API is forbidden.

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

[ad_2]

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments