IOS WKWebView Cross-Source Requests Supported for HTTP Only

Hi, I am trying to load an html that is in the main Bundle with WKWebView, which worked fine with UIWebView, but now I have an error, the files in html do not load sending the error in the console: "XMLHttpRequest cannot load"

Console Shape Simulator

Simulator

this is an example of http://proyectoshm.com/esferas/dosaguas/dosaguascitta.html nested content.

My code is:

let folder = "maquetas/esferas/\(esfera)" let resourcePath = Bundle.main.resourcePath let subdir = URL(fileURLWithPath:resourcePath!).appendingPathComponent(folder, isDirectory: true) guard let path = Bundle.main.path(forResource: "index", ofType: "html", inDirectory: folder) else { print("no se encontrΓ³ path") return } print(subdir.path) let url = NSURL.fileURL(withPath: path) print(url.path) vistaweb = WKWebView(frame: self.view.frame) vistaweb.loadFileURL(url, allowingReadAccessTo: subdir) self.view.addSubview(vistaweb) 
0
source share
1 answer

This code will help you in this case :)

 vistaweb.configuration.preferences.setValue(true, forKey: "allowFileAccessFromFileURLs") 
+3
source

Source: https://habr.com/ru/post/1274123/


All Articles