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

相关推荐
市民中心的蟋蟀几秒前
第十一章 这三个全局状态管理库之间的共性与差异 【上】
前端·javascript·react.js
小宋1021几秒前
el-table的select回显问题
javascript·vue.js·elementui
豆豆(设计前端)20 分钟前
在 JavaScript 中,你可以使用 Date 对象来获取 当前日期 和 当前时间、当前年份。
开发语言·javascript·ecmascript
DoraBigHead32 分钟前
深入 JavaScript 作用域机制:透视 V8 引擎背后的执行秘密
前端·javascript
薛定谔的算法33 分钟前
JavaScript闭包深度解析:从基础概念到柯里化实践
javascript
菥菥爱嘻嘻37 分钟前
React---Hooks深入
前端·javascript·react.js
只与明月听40 分钟前
前端学算法-二叉树(一)
前端·javascript·算法
谢尔登1 小时前
【React】使用 useContext + useReducer 实现一个轻量的状态管理库
前端·javascript·react.js
Bee.Bee.1 小时前
vue3提供的hook和通常的函数有什么区别
前端·javascript·vue.js
VisuperviReborn1 小时前
前端开发者的知识深度革命,从打牢基础开始
前端·javascript·架构