通过 https 的 React-native 加载图像有效,而 http 无效 [英] React-native loading image over https works while http does not work

查看:44
本文介绍了通过 https 的 React-native 加载图像有效,而 http 无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过 http uri 作为源在 iOS 模拟器中加载图像.但是除了可以通过检查器看到的线框之外,屏幕上没有显示任何内容.如果您在 Android 中加载相同的代码,它可以正常工作,如果您使用 https uri 而不是 http,它也可以正常工作.

I want to load an Image in the iOS simulator over a http uri as source. But nothing is shown on the screen expect the wireframe which can be made visible with the inspector. If you load the same code in Android it works fine and if you use a https uri instead of http it also works fine.

示例代码:

render() { 
  return ( 
   <View> 
     <Image 
       source={{uri:https://facebook.github.io/react/img/logo_og.png'}} // works  
    // source={{uri: http://facebook.github.io/react/img/logo_og.png'}}  // doesn't work
       style={{width: 400, height: 400}}   
     />   
  </View>  
 );  
}

推荐答案

问题是您正在尝试从 http 连接而不是从苹果要求的 https 连接加载图像.试试你的代码是否适用于另一个使用 https 而不是 http 的 uri.在 Android 中,它应该适用于 http 或 https.在 https://github.com/facebook/react-native/issues/8520http://www.techrepublic.com/article/wwdc-2016-apple-to-require-https-encryption-on-all-ios-apps-by-2017/.

The problem is that your are trying to load the image from a http connection and not from a https connection as it is demanded by apple. Try if your code works with another uri which uses https instead of http. In Android it should work fine with either http or https. Read more at https://github.com/facebook/react-native/issues/8520 and http://www.techrepublic.com/article/wwdc-2016-apple-to-require-https-encryption-on-all-ios-apps-by-2017/.

如果你真的想通过 http 加载一些东西,你可以编辑 info.plist 文件并在那里添加你的例外.此处有更多详细信息 https://ste.vn/2015/06/10/configuring-app-transport-security-ios-9-osx-10-11/

If you really want to load something over http you can edit the info.plist file and add your exception there. More detailed info here https://ste.vn/2015/06/10/configuring-app-transport-security-ios-9-osx-10-11/

这篇关于通过 https 的 React-native 加载图像有效,而 http 无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆