【问题标题】:react native Webview Process Terminated反应本机 Webview 进程终止
【发布时间】:2020-05-11 06:09:10
【问题描述】:

我正在使用 react native 在 web 视图上显示本地 HTML, 我注意到有时 webView 会随机崩溃,并且我会在控制台上收到消息:

Webview Process Terminated

我已经搜索过,但找不到任何答案? 那是什么?为什么会发生?出现该错误后如何避免或重新加载网页视图?

 <WebView
      style={styles.webContainer}
      originWhitelist={['*']}
      source={isAndroid ? {uri:'file:///android_asset/binaura.html'} : HTML_FILE}

      javaScriptEnabled={true}
          domStorageEnabled={true}

    />

【问题讨论】:

    标签: react-native webview


    【解决方案1】:

    如果“WebView”是指react-native-webview

    如果 WebView 使用太多资源,则会在 iOS 上发生这种情况,并导致 WebView 崩溃(显示空白页)或应用程序冻结。

    有一个回调属性onContentProcessDidTerminate(在this PR 中引入),您可以使用它来侦听终止并通过更新其键来强制重新加载WebView。这有点小技巧,但它确实有效。

    使用示例:

    class MyComponent extends Component {
      state = {
        webviewKey: 0,
      }
    
      reload() {
        this.setState({
          webviewKey: this.state.webviewKey + 1,
        })
      }
    
      render() {
        return (
          <WebView
            key={this.state.webviewKey}
            onContentProcessDidTerminate={this.reload}
          />
        )
      }
    }
    
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-05-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-05-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多