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

相关推荐
To_OC2 小时前
LC 560 和为 K 的子数组:前缀和配哈希表,这对组合我是真的服了
javascript·算法·程序员
明朝百晓生3 小时前
Deep RL learning[2026/8]
开发语言·javascript·人工智能
用户938515635073 小时前
ESLint 代码规范完全指南——从 AST 原理到 flat config 逐行解析
javascript·后端·代码规范
kyriewen5 小时前
今年裁了16万技术人——但字节前端岗反而涨了23%
前端·javascript·面试
王林不想说话7 小时前
ES6 到 ES2026 全面进阶指南:新特性、原理、示例与工程落地
前端·javascript·面试
WZzz7 小时前
JavaScript 中 this 的「指向」完整教程
javascript
mONESY7 小时前
浏览器里跑 DeepSeek-R1,这份 worker.js 到底写了什么
javascript
用户6919026813398 小时前
用浏览器 WebGPU跑DPSK大模型(1) - 模型的下载和前端下载进度的显示
javascript·react.js·架构
夏幻灵8 小时前
Vue 2 与 Vue 3 在应用初始化上的设计差异与技术演进
前端·javascript·vue.js
悟空瞎说9 小时前
Three.js 架构实践:用 MVC 模式组织你的 3D 应用
前端·javascript