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

相关推荐
Hello--_--World15 分钟前
Vue:虚拟Dom
前端·javascript·vue.js
bluetata1 小时前
AI 浪潮与破局:TypeScript 生态实战,让 AI 为你所用
javascript·人工智能·typescript
白鹿第一帅1 小时前
TypeScript+React 全栈生态实战:从架构选型到工程落地,告别开发踩坑
mongodb·react.js·架构·typescript·白鹿第一帅·架构选型·工程落地
布局呆星1 小时前
Vue Router 核心知识点梳理
前端·javascript·vue.js
JiaWen技术圈1 小时前
增量静态再生(ISR)详解:Next.js 中的实现与应用
javascript·git·ubuntu
张元清2 小时前
React 中的语音与摄像头输入:语音识别、媒体设备与权限
前端·javascript·面试
01漫游者2 小时前
JavaScript继承深度解析
开发语言·javascript·ecmascript
费曼学习法2 小时前
Vue 响应式系统源码级剖析:从 Object.defineProperty 到 Proxy
javascript·vue.js
神奇小汤圆3 小时前
快手一面:为什么要求用Static来修饰ThreadLocal变量?
javascript
行业研究员3 小时前
HTML头部元信息避坑指南大纲
javascript