reactNative跳转appstore链接报错:Redirection to URL with a scheme that is not HTTP(S)

在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下载界面报错问题

相关推荐
清沫15 分钟前
VSCode debugger 调试指南
前端·javascript·visual studio code
zhenryx2 小时前
React Native 自定义 ScrollView 滚动条:开箱即用的 IndicatorScrollView(附源码示例)
javascript·react native·react.js·typescript
GISer_Jing2 小时前
2025年Flutter与React Native对比
android·flutter·react native
振华OPPO3 小时前
Vue:“onMounted“ is defined but never used no-unused-vars
前端·javascript·css·vue.js·前端框架
拉不动的猪4 小时前
try...catch 核心与生态协作全解析
前端·javascript·vue.js
Xeon_CC4 小时前
在react-app-rewired工程项目中,调试AntVG6库源码包。
前端·react.js·前端框架
摇滚侠5 小时前
Vue 项目实战《尚医通》,预约挂号的路由与静态搭建,笔记36
javascript·vue.js·笔记
码上成长5 小时前
React 18 并发特性:useTransition 和 useDeferredValue 动画级解释
javascript·react.js·ecmascript
G***T6916 小时前
React性能优化实战,避免不必要的重渲染
前端·javascript·react.js
网络点点滴6 小时前
标签的ref属性
前端·javascript·vue.js