在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函数中文章来源:https://www.toymoban.com/news/detail-641761.html
<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下载界面报错问题文章来源地址https://www.toymoban.com/news/detail-641761.html
到了这里,关于reactNative跳转appstore链接报错:Redirection to URL with a scheme that is not HTTP(S)的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!