赞
踩
在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函数中
- <WebView
- ref={webViewRef}
- startInLoadingState
- renderLoading={() => (
- <View style={styles.loadingContainer}>
- <Lottie
- source={require('./loading.json')}
- autoPlay
- loop
- style={{ 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下载界面报错问题
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。