在reactnative中webview跳转H5下载页面,包错Redirection to URL with a scheme that is not HTTP(S)
在webview中添加一下代码
const onShouldStartLoadWithRequest = (event: any) => {const { url } = event;console.log(url);if (url.startsWith('https://itunes.apple.com')) {Linking.canOpenURL(url).then(res => {if (res) {Linking.openURL(url);}});return false;}return true; // 允许WebView加载其他链接};
render函数中
<WebViewref={webViewRef}startInLoadingStaterenderLoading={() => (<View style={styles.loadingContainer}><Lottiesource={require('./loading.json')}autoPlayloopstyle={{ width: 150, height: 150 }}/></View>)}source={{ uri: route?.params?.uri }}onLoadEnd={() => {// 在Vue 3页面加载完成后,再发送数据sendDataToVue({messageCenter: data,rnApp: true,location: location,});}}onMessage={handlemessage}injectedJavaScript={`window.postMessage(${JSON.stringify(JSON.stringify({messageCenter: data,rnApp: true,location: location,}),)})`}originWhitelist={['*']}style={styles.container}onShouldStartLoadWithRequest={onShouldStartLoadWithRequest}/>
onShouldStartLoadWithRequest={onShouldStartLoadWithRequest}是关键,可以解决ios跳转appstore下载界面报错问题