当前位置:   article > 正文

reactNative跳转appstore链接报错:Redirection to URL with a scheme that is not HTTP(S)_react native 跳转应用商城

react native 跳转应用商城

reactnative中webview跳转H5下载页面,包错Redirection to URL with a scheme that is not HTTP(S)
webview中添加一下代码
 

  1. const onShouldStartLoadWithRequest = (event: any) => {
  2. const { url } = event;
  3. console.log(url);
  4. if (url.startsWith('https://itunes.apple.com')) {
  5. Linking.canOpenURL(url).then(res => {
  6. if (res) {
  7. Linking.openURL(url);
  8. }
  9. });
  10. return false;
  11. }
  12. return true; // 允许WebView加载其他链接
  13. };

render函数中

  1. <WebView
  2. ref={webViewRef}
  3. startInLoadingState
  4. renderLoading={() => (
  5. <View style={styles.loadingContainer}>
  6. <Lottie
  7. source={require('./loading.json')}
  8. autoPlay
  9. loop
  10. style={{ width: 150, height: 150 }}
  11. />
  12. </View>
  13. )}
  14. source={{ uri: route?.params?.uri }}
  15. onLoadEnd={() => {
  16. // 在Vue 3页面加载完成后,再发送数据
  17. sendDataToVue({
  18. messageCenter: data,
  19. rnApp: true,
  20. location: location,
  21. });
  22. }}
  23. onMessage={handlemessage}
  24. injectedJavaScript={`window.postMessage(${JSON.stringify(
  25. JSON.stringify({
  26. messageCenter: data,
  27. rnApp: true,
  28. location: location,
  29. }),
  30. )})`}
  31. originWhitelist={['*']}
  32. style={styles.container}
  33. onShouldStartLoadWithRequest={onShouldStartLoadWithRequest}
  34. />

onShouldStartLoadWithRequest={onShouldStartLoadWithRequest}是关键,可以解决ios跳转appstore下载界面报错问题

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Cpp五条/article/detail/421009
推荐阅读
相关标签
  

闽ICP备14008679号