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

相关推荐
万少1 小时前
万少的博客 - 技术分享与解决方案
前端·javascript·后端
尘世中一位迷途小书童4 小时前
用 Cesium 撸了一个森林火情监控大屏,弧线、粒子、发光效果都齐了
前端·javascript
先吃饱再说5 小时前
JavaScript中`this` 的“千层套路”:从默认绑定到箭头函数的五种指向
javascript
foxire5 小时前
基于nodejs实现服务端内核引擎
javascript
CaffeinePro7 小时前
告别知识点零散!React零基础通关,从环境搭建到Ant Design页面实战
前端·react.js
触底反弹8 小时前
🧠 搞懂 Token,才算真正入门大模型——从分词原理到 Embedding 语义实战
javascript·人工智能·算法
free358 小时前
AST Interpreter 的设计:为什么分 evaluate() 和 execute()
javascript
等咸鱼的狸猫8 小时前
JavaScript 隐式类型转换:从入门到精通
javascript
kyriewen11 小时前
我用 Codex 重写了同事维护三年的代码,他没说谢谢——而是找了领导
前端·javascript·ai编程
铁皮饭盒11 小时前
S3已成为文件存储标准,阿里/腾讯/华为云都支持,Bun率先原生支持
前端·javascript·后端