https上的React-native加载图像可以正常工作,而http不起作用 [英] React-native loading image over https works while http does not work

查看:440
本文介绍了https上的React-native加载图像可以正常工作,而http不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在iOS模拟器中通过http uri作为源加载图像。但是屏幕上没有显示任何可以通过检查员看到的线框。
如果你在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/ issue / 8520 http://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天全站免登陆