React Native静态图像don'脱机捆绑时不会显示在应用程序中

React-Native Static images don't show up in app on offline bundling

本文关键字:显示 应用程序 脱机 图像 静态 Native don React      更新时间:2023-09-26

我做了以下

  1. 评论

    jsCodeLocation=[NSURL URLWithString:@"localhost:8081/index.ios.bundle?platform=ios&dev=true"];

  2. 未注释

    jsCodeLocation=[[NSBundle mainBundle]URLForResource:@"main"withExtension:@"jsbundle"];

然后从根目录运行以下命令,其中index.ios.js是

react-native bundle --dev false --entry-file index.ios.js --bundle-output ios/main.jsbundle --assets-dest ios/ --verbose

然后,从XCode,我将main.jsbundle添加到项目中(project>RightClick>Add files…),但我不确定将运行该命令创建的assets文件夹放在哪里,我尝试用相同的方法将assets文件夹添加到项目,但静态图像仍然不会显示在编译的二进制文件中。我将资产文件夹放在哪里?

与其运行bundle命令并生成bundle和资产,还有一种更好的方法。

请按照此处"手动升级"部分的说明进行操作https://facebook.github.io/react-native/docs/upgrading.html#from-0-13至0-14

更改方案以发布

通过取消的注释,在Appdelegate.m中选择选项2

就是这样,现在您可以在不运行开发服务器的情况下在物理设备上运行应用程序。