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

相关推荐
我是伪码农2 分钟前
动态表格案例
前端·javascript·html
用户81686947472510 分钟前
Context API 的订阅机制与性能优化
前端·react.js
异界蜉蝣14 分钟前
React Fiber架构:Diff算法的演进
前端·react.js·前端框架
追梦_life15 分钟前
localStorage使用不止于getItem、setItem、removeItem
前端·javascript
全栈陈序员16 分钟前
请描述下你对 Vue 生命周期的理解?在 `created` 和 `mounted` 中请求数据有什么区别?
前端·javascript·vue.js·学习·前端框架
无限大616 分钟前
用三行代码实现圣诞树?别逗了!让我们来真的
前端·javascript
拉姆哥的小屋20 分钟前
深度剖析SentiWordNet情感词典:155,287单词的情感世界
前端·javascript·easyui
T___T22 分钟前
从 0 搭建 React 待办应用:状态管理、副作用与双向绑定模拟
前端·react.js·面试
林太白27 分钟前
vue3这些常见指令你封装了吗
前端·javascript
Tzarevich39 分钟前
算法效率的核心:时间复杂度与空间复杂度
javascript·算法