Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting "Disable web security" and "allow file access from files" in iOS WKWebView

How to disable web security in iOS WKWebView? I used command "open /Applications/Google\ Chrome.app --args --disable-web-security --allow-file-access-from-files" in mac system to open the chrome. But How to do this in WKWebView? Thankes!

like image 697
Huanrong Avatar asked Mar 15 '16 14:03

Huanrong


1 Answers

It's not possible to disable web security in WKWebView - there's no preference to do so - see the iOS source code for WebKit preferences.

There is a way to allow access from file URLs, although it's not officially supported. In the source code, a preference exists, so you can set it like this:

[wkWebView.configuration.preferences setValue:@TRUE forKey:@"allowFileAccessFromFileURLs"];

This enables access to file URLs relative to the content src. e.g. if the local page is foo/bar/index.html you can access files in foo/bar/ (e.g. foo/bar/1.jpg or foo/bar/sub/2.jpg) but not outside (e.g. foo/other/3.jpg or Documents/NoCloud/4.jpg).

like image 66
DaveAlden Avatar answered Oct 28 '22 10:10

DaveAlden