I am working on hybrid ios application,i am trying to use wkwebview instead of uiwebview,because in wkwebview they fixed lot of performance issues over uiwebview,and the speed of loading also increased in wkwebview,if i am making any ajax request from supporting files ,i am getting Origin null is not allowed by Access-Control-Allow-Origin
code:
NSString *htmlFile = [[NSBundle mainBundle] pathForResource:@"sample" ofType:@"html"];
NSString* htmlString = [NSString stringWithContentsOfFile:htmlFile encoding:NSUTF8StringEncoding error:nil];
[webView loadHTMLString:htmlString baseURL: [[NSBundle mainBundle] bundleURL]];
The next code solved the issue for me.
func loadWKWebview(){
let configs = WKWebViewConfiguration()
configs.setValue(true, forKey: "_allowUniversalAccessFromFileURLs")
let webView = WKWebView(frame: view.bounds, configuration: configs)
self.view.addSubview(webView)
let request = URLRequest(url: Bundle.main.url(forResource: "hello", withExtension: "html")!)
webView.load(request)
}
Pay attention that the configuration setup has to be done Prior to WKWebView instantiation
Taken from cordova-ios
in CordovaLib/Classes/Private/Plugins/CDVWebViewEngine/CDVWebViewEngine.m after WKWebViewConfiguration* configuration = [[WKWebViewConfiguration alloc] init]; add the following: [configuration setValue:@"TRUE" forKey:@"allowUniversalAccessFromFileURLs"];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With