设置“禁用网络安全”和“允许从文件访问文件”在iOS WKWebView中 [英] Setting "Disable web security" and "allow file access from files" in iOS WKWebView
问题描述
如何在iOS WKWebView中禁用Web安全性?我在mac中使用了命令open / Applications / Google \ Chrome.app --args --disable-web-security --allow-file-access-from-files系统打开铬。但是如何在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!
推荐答案
在WKWebView中无法禁用Web安全性 - 没有优先选择 - 请参阅 WebKit偏好的iOS源代码。
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.
有一种方法允许从文件URL进行访问,尽管它没有得到官方支持。在源代码,存在首选项,因此您可以这样设置:
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"];
这样可以访问相对于内容src的文件URL。例如如果本地页面是 foo / bar / index.html
,您可以访问 foo / bar /
中的文件(例如 foo / bar / 1.jpg
或 foo / bar / sub / 2.jpg
)但不在外面(例如 foo / other / 3.jpg
或 Documents / NoCloud / 4.jpg
)。
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
).
这篇关于设置“禁用网络安全”和“允许从文件访问文件”在iOS WKWebView中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!