繁体   English   中英

如何为 React Native 构建 .ipa?

[英]How to build .ipa for React Native?

我是在没有 iOS 开发经验的情况下来到 React Native 开发的。 我想构建发布。 .ipa 文件 - 理想情况下来自命令行,但在设备运行的官方文档非常简短。

我能够通过 XCode 在我的 iPhone 上手动部署应用程序,但仍然找不到任何“发布 IPA”文件。 我已经用#ifdef DEBUG指令更新了我的代码,使其更通用。

有没有办法仅通过命令行在发布模式下构建应用程序? 如果不是,生成 RN 应用程序的“官方”方式是什么?

我目前正在使用 RN 0.20。

首先,您需要以这种方式创建一个包:

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

然后,您必须在 AppDelegate.m 中注释此行:

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

并取消注释这个:

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

然后你必须在 Xcode 中选择 Product -> Archive 并根据你想要的版本按照步骤操作

您必须将 Scheme 设置为 Release。

从文档中,您有两种方法。

为此,请转到 Product → Scheme → Edit Scheme (cmd + <),确保您位于侧面的 Run 选项卡中,并将 Build Configuration 下拉列表设置为 Release。

或者

您还可以使用 React Native CLI 使用选项 --configuration 和 Release 值来执行此操作(例如 react-native run-ios --configuration Release)。

然后你可以像往常一样生成你的档案。

https://facebook.github.io/react-native/docs/running-on-device.html#building-your-app-for-production

我无法对上述答案发表评论,这是正确的,但您需要从以下命令开始才能使其正常工作:

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

区别在于“ios”而不是“iOS”

如果不是,它会给出以下错误:

ProjectPath/node_modules/promise/lib/done.js:10
  throw err;
  ^

IOS

  1. 使用根文件夹中的以下简单命令,使用 Xcode 打开 iOS 项目。

     xed ./ios
  2. 现在将以下命令粘贴到终端中

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

    在此处输入图片说明

  3. 像这样从 Xcode 编辑方案:

    产品 -> 方案 -> 编辑方案

    在此处输入图片说明

    编辑方案发布

    在此处输入图片说明

现在您有了一个独立的 Xcode 项目,并准备像原生 Xcode 项目一样构建/发布。

来自: https : //medium.com/better-programming/create-ipa-and-apk-from-react-native-72fe53c6a8db

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM