我正在使用 native 0.28.0
我正在尝试根据本教程在iPhone模拟器上显示图像:
Introduction to React Native: Building iOS Apps with JavaScript | Appcoda

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连接而不是从Apple要求的https连接加载图像。
请尝试将您的代码与另一个使用https而不是http的uri一起使用。
在Android中,它可以与http或https正常工作。
进一步了解
https://github.com/facebook/react-native/issues/8520WWDC 2016: Apple to require HTTPS encryption on all iOS apps by 2017
如果您确实想通过http加载某些内容,则可以编辑info.plist文件并在其中添加异常(exception)。更详细的信息在这里:Configuring App Transport Security Exceptions in iOS 9 and OSX 10.11
另请参阅我的StackOverflow问题:React-native loading image over https works while http does not work

关于ios - 在React Native iOS Simulator中无法通过URI显示图像,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/38136981/

10-12 00:16
查看更多