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

相关推荐
float_六七13 分钟前
Spring AOP表达式速查手册
前端·javascript·spring
DsirNg16 分钟前
JavaScript 事件循环机制详解及项目中的应用
开发语言·javascript·ecmascript
LisEcho18 分钟前
yoyoj-rn — RN 的脚手架工具可以不是 @react-native-community/cli
前端·react native·npm
如果你好19 分钟前
一文搞懂 JavaScript 原型链:从本质到实战应用
前端·javascript
Tzarevich20 分钟前
从命令式到声明式:用 Vue 3 构建任务清单的开发哲学
javascript·vue.js·响应式编程
研☆香22 分钟前
深入解析JavaScript的arguments对象
开发语言·前端·javascript
parksben24 分钟前
告别 iframe 通信的 “飞鸽传书”:Webpage Tunnel 上手指南
前端·javascript·前端框架
全栈前端老曹24 分钟前
【前端权限】 权限变更热更新
前端·javascript·vue·react·ui框架·权限系统·前端权限
写代码的皮筏艇25 分钟前
react中的useCallback
前端·javascript
用户81686947472527 分钟前
Fiber 双缓存架构与 Diff 算法
前端·react.js