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

相关推荐
传人once7 小时前
页面中心圆圈放大效果如何写
开发语言·javascript·ecmascript
enjoywindstorm8 小时前
移动端原生框架对比评测
react native
光影少年9 小时前
为什么 JavaScript 中 0.1 + 0.2 !== 0.3,如何让其相等?
前端·javascript·算法
梓雨枔11 小时前
JavaScript+快速学习,简单好用~
javascript·学习
木易 士心11 小时前
JavaScript 闭包原理和实践深度解析
开发语言·javascript·ecmascript
ITOM运维行者11 小时前
PHP性能监控怎么做?从响应时间到慢函数的6个关键指标
前端·javascript·后端
hai_android12 小时前
一个公式看懂动态跨表查找:P8 + VLOOKUP
前端·javascript·vue.js
杨利杰YJlio12 小时前
Tibo的28天计划DAY1GPT-6提速50%意味着什么?
前端·javascript·后端
鬼手点金13 小时前
opencode-全能开发者配置
java·linux·服务器·前端·javascript·学习·前向传播
晴天小庭13 小时前
Sael——基于Jev的AI中转站的安全风控网关,现已开源
人工智能·后端·react.js