生产中的 Expo Webview 显示 ERR_UNKNOWN_URL_SCHEME
Expo Webview in Production shows ERR_UNKNOWN_URL_SCHEME
我有一个 HTML 代码,其中注入了 Javascript,可以执行并启动验证服务。它在开发模式下工作得很好,但在生产模式下却不行。
<WebView
allowFileAccess={true}
source={(getSource(file))}
javaScriptEnabled={true}
injectedJavaScript={script}
originWhitelist={["https://*", "http://*", "file://*", "asset://*"]}
/>
const download = async () => {
let file = Asset.fromModule(html);
if (file.localUri !== null) {
return file
}
await file.downloadAsync() // Optional, saves file into cache
console.log('file', file)
return file
}
const getSource = (file) => {
if (Platform.OS !== 'android') {
return html
}
if (file === null) {
return {}
}
return {
uri: file.localUri
}
}
关注此 tutorial 我遇到了同样的问题。首先,您需要更改 android 上的文件位置,因为在独立版本中,文件位于 android_assets
下。所以即使 localuri 说了一件事,它实际上并不在那个位置。
并且您需要确保在构建时也捆绑了 html 文件。 expo 应用程序中的一切都运行良好,因为您在本地访问内容,但一旦您构建了独立应用程序,情况就不同了。我希望这有帮助。我花了一个星期才终于开始工作,那篇文章很有帮助。
我有一个 HTML 代码,其中注入了 Javascript,可以执行并启动验证服务。它在开发模式下工作得很好,但在生产模式下却不行。
<WebView
allowFileAccess={true}
source={(getSource(file))}
javaScriptEnabled={true}
injectedJavaScript={script}
originWhitelist={["https://*", "http://*", "file://*", "asset://*"]}
/>
const download = async () => {
let file = Asset.fromModule(html);
if (file.localUri !== null) {
return file
}
await file.downloadAsync() // Optional, saves file into cache
console.log('file', file)
return file
}
const getSource = (file) => {
if (Platform.OS !== 'android') {
return html
}
if (file === null) {
return {}
}
return {
uri: file.localUri
}
}
关注此 tutorial 我遇到了同样的问题。首先,您需要更改 android 上的文件位置,因为在独立版本中,文件位于 android_assets
下。所以即使 localuri 说了一件事,它实际上并不在那个位置。
并且您需要确保在构建时也捆绑了 html 文件。 expo 应用程序中的一切都运行良好,因为您在本地访问内容,但一旦您构建了独立应用程序,情况就不同了。我希望这有帮助。我花了一个星期才终于开始工作,那篇文章很有帮助。