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

相关推荐
乐多_L1 小时前
使用vue3框架vue-next-admin导出表格excel(带图片)
前端·javascript·vue.js
南望无一1 小时前
React Native 0.70.x如何从本地安卓源码(ReactAndroid)构建
前端·react native
纯粹要努力2 小时前
前端跨域问题及解决方案
前端·javascript·面试
小刘不知道叫啥2 小时前
React源码揭秘 | 启动入口
前端·react.js·前端框架
HsuYang2 小时前
Vite源码学习(十二)——热更新(下)
前端·javascript·架构
csdn_aspnet2 小时前
JavaScript AJAX 库
javascript·ajax
胡桃不是夹子2 小时前
vue登陆下拉菜单
前端·javascript·vue.js
大G哥2 小时前
用DeepSeek来帮助学习three.js加载3D太极模形
开发语言·前端·javascript·学习·ecmascript
锐小制2 小时前
十分钟学习编写Ridge页面脚本
前端·javascript
丁总学Java5 小时前
Mac arm架构使用 Yarn 全局安装 Vue CLI
前端·javascript·vue.js