I load local html file on IOS WKWebview
using loadFileURL: allowingReadAccessToURL
.. But when I send ajax request, it fails.
The error is:
Origin null is not allowed by Access-Control-Allow-Origin.
Can I set some properties to fix this error, like in Android,we can use setAllowUniversalAccessFromFileURLs
?
Have you tried setting it like this?
let config = WKWebViewConfiguration() config.setValue(true, forKey: "allowUniversalAccessFromFileURLs")
When HTML is loaded locally (file URL) with WkWebView below configuration setting to WkWebView worked for me
WKWebViewConfiguration *theConfiguration = [[WKWebViewConfiguration alloc] init]; WKUserContentController *userContentController = [[WKUserContentController alloc] init]; [theConfiguration.preferences setValue:@"TRUE" forKey:@"allowFileAccessFromFileURLs"]; [theConfiguration setValue:@"TRUE" forKey:@"allowUniversalAccessFromFileURLs"];
When you set above setting, origin will be passed as "file://" instead of null
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