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

相关推荐
Y42582 小时前
本地多语言切换具体操作代码
前端·javascript·vue.js
fruge3 小时前
React 2025 完全指南:核心原理、实战技巧与性能优化
javascript·react.js·性能优化
etsuyou5 小时前
js前端this指向规则
开发语言·前端·javascript
不想上班只想要钱6 小时前
vue3+vite创建的项目,运行后没有 Network地址
前端·javascript·vue.js
浮游本尊7 小时前
React 18.x 学习计划 - 第四天:React Hooks深入
前端·学习·react.js
JS.Huang9 小时前
【JavaScript】原生函数
开发语言·javascript·ecmascript
533_9 小时前
[vue] dayjs 显示实时时间
前端·javascript·vue.js
ftpeak10 小时前
JavaScript性能优化实战
开发语言·javascript·性能优化
一个很帅的帅哥11 小时前
JavaScript事件循环
开发语言·前端·javascript
fox_11 小时前
深入理解React中的不可变性:原理、价值与实践
前端·react.js