在 React-Native 的 WebView 中引用路径时访问被拒绝

Access Denied while referencing path in WebView of React-Native

所以我使用 React-native WebView 来显示本地 html 文件。我的文件位于 /storage/emulated/0/Android/data/com.package/files/sample.html。我已经使用 React-Native-fs 在此位置写入文件。

现在我有一个 webview 声明为:

<WebView source={{uri : 'file:///storage/emulated/0/Android/data/com.package/files/sample.html'}}/>

因此,每当我 运行 这个时,WebView 都会向我显示显示 net::ERR_ACCESS_DENIED 的页面。如果我使用 React-Native-fs readfile 从该路径读取文件,我可以做到。为什么我无法访问 webView 中的文件路径?

终于修好了。 allowFileAccess 是 WebView 的一个属性,默认设置为 false。将其设置为 true 允许它从任何地方访问 .html 文件

这就是文档所说的 Boolean that sets whether the WebView has access to the file system. The default value is false.