我必须将图像下载到我的iOS应用本地文件系统中,然后将其读回。
在我的模拟器上,我可以看到带有目录的应用程序文件系统
/Library/Developer/CoreSimulator/Devices/[UUID]/data/Containers/Data/Application/[UUID]/
/Documents
/Library
/tmp
为了尝试,我将foo.png复制到/ Documents文件夹,然后尝试
<Image source={{uri: "file://Documents/foo.png"}} style={{width:100, height:100}}/>
这是行不通的,任何想法怎么做都可以。
这也花了我很长时间...更好的信息将是5分钟!
我使用react-native-fs来获取目录(适用于ios和android):
var RNFS = require('react-native-fs');
然后,RNFS.DocumentDirectoryPath返回类似于'/var/mobile/Containers/Data/Application/15AC1CC6-8CFF-48F0-AFFD-949368383ACB/Documents'
iOS上的内容
我的图片元素看起来像:
<Image
style={{width:100, height:100}}
source={{uri: 'file://' + RNFS.DocumentDirectoryPath + '/myAwesomeSubDir/my.png', scale:1}}
/>
我的问题是我没有首先设置宽度和高度,URL或资产路径并不需要设置宽度和高度。当使用base64 uri时,宽度和高度也是必须的(这实际上使我想到了解决方案!)。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句