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

相关推荐
an86950012 小时前
vue新建项目
前端·javascript·vue.js
czhc11400756634 小时前
c# 1121 构造方法
java·javascript·c#
GISer_Jing5 小时前
3D Cesium渲染架剖析
javascript·3d·webgl
han_5 小时前
前端性能优化之CSS篇
前端·javascript·性能优化
z***I3946 小时前
JavaScript爬虫应用案例
开发语言·javascript·爬虫
清风徐来QCQ7 小时前
javaScript(map,ref,?,forEach,watch)
java·前端·javascript
星月前端7 小时前
[特殊字符]面向 ArcGIS for JavaScript(4.x)开发者的「坐标系统(CRS / 投影)」全面解读
开发语言·javascript·arcgis
星空的资源小屋8 小时前
永久删除文件利器:Permadelete
java·javascript·人工智能
柒昀8 小时前
Vue.js
前端·javascript·vue.js
进阶的鱼8 小时前
React+ts+vite脚手架搭建(五)【登录篇】
前端·javascript