React-Native webview - IOS 中未处理的承诺 about:blank

React-Native webview - unhandled promise about:blank in IOS

同一个网站在 android 中运行得非常好,但是在 iOS 中似乎出现了这条消息:

Possible Unhandled Promise Rejection (id:11): Error: Unable to open URL about:blank

当站点 URI 链接到来自不同域的 URL 时,我似乎也明白了这一点。

我试过添加:originWhitelist={['*']}

这是 Webview 代码:

<WebView
        style={styles.flexContainer}
        startInLoadingState
        renderLoading={() => 
          <View style={styles.container}>
            <ActivityIndicator size="large" color="#ffffff" styles={styles.loader}/>
          </View>
        }
        onMessage={event => {
          parseWebData(event.nativeEvent.data);
        }}
        onShouldStartLoadWithRequest={event => {  
          if (!event.url.startsWith(base)) {
              Linking.openURL(event.url)
              return false
          }
          return true
          }}
      originWhitelist = {['*']}
      source = {{ uri: base + uri }}
        />

第一次尝试这个

<WebView
  source={{ uri: base + uri }}
  style={{ height: 400, width: 400 }}
  useWebKit={true}
  startInLoadingState={false}
  javaScriptEnabled
  domStorageEnabled
/>
   onShouldStartLoadWithRequest={event => {  
          if (!event.url.startsWith(base)) {
              Linking.openURL(event.url)
              return false
          }
          return true
          }}

这就是问题所在。

iOS 处理任何 URL 负载,而 Android 仅在点击时触发。

请参阅此 post 以了解问题的解释: onShouldStartLoadWithRequest automatically calling in iOS React Native on loading of any url in WebView, How to control it?