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

相关推荐
Csvn5 小时前
原型链、this 与闭包内存:三座深水区一次打通(含内存泄漏排查实战)
前端·javascript
万维易源5 小时前
趣味项目素材|免费脑筋急转弯查询接口实战接入教程
javascript·免费api·脑筋急转弯查询·脑筋急转弯接口
SLD_Allen8 小时前
Go语言runtime全景
开发语言·javascript·golang
风萧何8 小时前
架构艺术,是权衡的艺术。
前端·javascript·架构
偷偷挖矿的牛马矿工8 小时前
execa NodeJs新一代child_process的强力替代品
javascript
Shinner欣儿9 小时前
React18 和 19 新特性结合看
前端·react.js
水獭比特9 小时前
工作流都公开了,为什么还不能继承 Owner 权限?
javascript·人工智能·node.js
光影少年11 小时前
react navite环境与工程化
前端·react native·react.js
ly768911 小时前
Vue 3 从入门到工程实践:基础语法、组件化、路由、状态管理与项目部署
前端·javascript·vue.js