swift – Is ‘allowFileAccessFromFileURls’ still available on iOS WebKit?


I need to display ‘index.html’ in the webkit view within the iOS project. So I added a web project folder within the iOS project.

enter image description here

file tree

 if let url = Bundle.main.url(forResource: "index", withExtension: "html", subdirectory: "webmap") {
     self.webkit.loadFileURL(url, allowingReadAccessTo: url)
 }

Code that shows index.html in Webkit

I’m encountering an issue where my ‘index.html’ file recognizes JavaScript files but is unable to recognize certain resources, such as ‘icon_flag_my.png’.

‘Origin null is not allowed by Access-Control-Allow-Origin. Status code: 0’

‘[Error] Cannot load image file:///private/var/containers/Bundle/Application/510539…BBF34F90/iOSProject.app/webProj/img/icon_flag_my.png due to access control checks.

‘[Error] Failed to load resource: Origin null is not allowed by Access-Control-Allow-Origin. Status code: 0 (icon_flag_my.png, line 0)’

But I solved this problem through ‘allowFileAccessFromFileURls’.

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

I’m not certain whether it’s safe to use ‘allowFileAccessFromFileURls’.

The device I’m testing right now is iOS 17.2, and it works fine. But I looked it up and some people said it doesn’t work on iOS 15.6. Will it be different by version?

I also know it’s a feature that Apple doesn’t officially support. Some people say it doesn’t matter during the Apple App Store review process, is it true??

I want the current information, specifically concerning whether ‘allowFileAccessFromFileURLs’ is safe to use and whether apps using it have successfully passed Apple’s App Review.

It’s still too early to submit the review to Apple because it’s in the project development stage.

Latest articles

spot_imgspot_img

Related articles

Leave a reply

Please enter your comment!
Please enter your name here

spot_imgspot_img