【问题标题】:React Native ios not showing local imageReact Native ios不显示本地图像
【发布时间】:2020-02-09 21:22:18
【问题描述】:

环境

  • macOS:10.14.6
  • Xcode:11.0
  • 反应:16.8.6
  • 反应原生:0.60.5
  • 项目文件夹结构:google drive image link

背景

我做了一个简单的应用程序。我在 Android/iOS 模拟器和真实设备上对其进行了测试。 一切都很好。现在我正在尝试在 App Store 上进行部署。

问题

我将 Xcode 上的构建方案从调试更改为发布(产品 -> 方案 -> 编辑方案 -> 运行 -> 构建配置)。 我在模拟器上运行它。结果是this(google drive image link)

我不知道为什么我的应用无法加载静态图片。 如果我将方案更改为调试,它会像this(google drive image link) 一样显示。

也许...?

  1. 删除 ios 文件夹中的 main.jsbundle 文件后,我收到此错误 /Users/mac88/Desktop/Projects/팀포크봇/VoiceCarRN/ios/main.jsbundle: No such file or directory
  2. 2019-10-13 02:09:06.046867+0900 VoiceCarRN[44601:3301900] [PERF ASSETS] Loading image at size {854, 1334}, which is larger than the screen size {750, 1334}

请检查!

【问题讨论】:

    标签: ios xcode react-native deployment


    【解决方案1】:

    在项目内部使用此命令将断言从应用程序复制到 ios 文件夹

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

    请安装 react-native cli 以运行上述命令。

    对于这个警告

    Loading image at size {854, 1334}, which is larger than the screen size {750, 1334}
    

    只需在图像样式中添加 resizeMode: 'contain'

    【讨论】:

      【解决方案2】:

      使用此命令创建 jsbundle 和 assets 文件夹后

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

      您必须将它们都包含在Build Phases 中的Copy Bundle Resources 步骤中,因为您是在发布配置中运行应用程序。

      【讨论】:

      • 感谢您的帮助,每次我为 ios 制作 react-native 应用程序时都需要这个过程吗?还是我在 react-native 配置中出了什么问题?
      • 每次在 xCode 中以发布配置构建应用时都需要这样做。
      【解决方案3】:

      真正的原因是索引 .tsx 文件。

      我正在使用 typescript,并且我使用了 index.tsx。

      我将 index.tsx 更改为索引 .js 并且图像正确显示!

      【讨论】:

        【解决方案4】:

        我认为这是您的 xcode 版本的问题。所以尝试更新 xcode 11.7 并且不要使用 Beta 版本来构建 React Native。我和你有同样的问题,因为我使用 Xcode 12 https://developer.apple.com/forums/thread/652406

        【讨论】:

          【解决方案5】:

          在您的 package.json 文件中添加/修改此命令

          “build:ios”: “react-native bundle --entry-file=‘index.js’ --bundle-output=‘./ios/main.jsbundle’ --assets-dest ./ios/release --dev=false --platform=‘ios’”
          

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2021-01-05
            • 2023-01-16
            • 2016-05-23
            • 1970-01-01
            • 1970-01-01
            • 2022-01-01
            相关资源
            最近更新 更多