我正在开发Expo的React Native应用程序。我将项目弹出到ExpoKit并添加了react-native-wkwebview-reborn。我遇到这个库的一些问题,因为总是会出现此错误:
这是我的代码:
ContentWebView.ios.js
render() {
return (
<View style={styles.container}>
<WKWebView
ref={WEBVIEW_REF}
sendCookies={true}
style={styles.webview}
source={{uri: this.props.url}}
allowsLinkPreview={false}
onMessage={(e) => this._handleMessage(e)}
onNavigationStateChange={(e) => this._onNavigationStateChange(e)}
/>
这是我的应用崩溃的地方:
_onNavigationStateChange(e) {
this.refs[WEBVIEW_REF].evaluateJavaScript('window.postMessage({cookies: document.cookie}); clearInterval(window.myCartInterval); window.myCartInterval = setInterval(function(){window.postMessage({cookies: document.cookie});},5000);');
}
如果您有任何想法,它将非常有用!谢谢
最佳答案
你可以尝试更改代码吗?
尝试这种方式。
<WKWebView
ref={WEBVIEW_REF => {this.webview = WEBVIEW_REF;}}
sendCookies={true}
style={styles.webview}
source={{uri: this.props.url}}
allowsLinkPreview={false}
onMessage={(e) => this._handleMessage(e)}
onNavigationStateChange={(e) => this._onNavigationStateChange(e)}
/>
...
_onNavigationStateChange(e) {
this.webview.evaluateJavaScript('window.postMessage(e)');
}