简体   繁体   English

如何为 React Native 构建 .ipa?

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

I come to React Native development without previous experience in iOS development.我是在没有 iOS 开发经验的情况下来到 React Native 开发的。 I want to build release.我想构建发布。 .ipa file - ideally from the command line but the official documentation Running On Device is very brief. .ipa 文件 - 理想情况下来自命令行,但在设备运行的官方文档非常简短。

I was able to deploy applications on my iPhone manually via XCode but still, I can't find any "release IPA" file.我能够通过 XCode 在我的 iPhone 上手动部署应用程序,但仍然找不到任何“发布 IPA”文件。 I have updated my code with #ifdef DEBUG directives to make it more generic.我已经用#ifdef DEBUG指令更新了我的代码,使其更通用。

Is there a way to build an application in release mode only via the command-line?有没有办法仅通过命令行在发布模式下构建应用程序? If no, what is "the official" way to generate an RN application?如果不是,生成 RN 应用程序的“官方”方式是什么?

I am currently using RN 0.20.我目前正在使用 RN 0.20。

First, you need to create a bundle this way :首先,您需要以这种方式创建一个包:

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

Then, you have to comment this line in AppDelegate.m :然后,您必须在 AppDelegate.m 中注释此行:

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

and uncomment this one :并取消注释这个:

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

Then you have to go for Product -> Archive in Xcode and follow the steps based on your desired release然后你必须在 Xcode 中选择 Product -> Archive 并根据你想要的版本按照步骤操作

You have to set Scheme to Release.您必须将 Scheme 设置为 Release。

From docs you have two ways.从文档中,您有两种方法。

To do this, go to Product → Scheme → Edit Scheme (cmd + <), make sure you're in the Run tab from the side, and set the Build Configuration dropdown to Release.为此,请转到 Product → Scheme → Edit Scheme (cmd + <),确保您位于侧面的 Run 选项卡中,并将 Build Configuration 下拉列表设置为 Release。

or或者

You can also use the React Native CLI to perform this operation using the option --configuration with the value Release (eg react-native run-ios --configuration Release).您还可以使用 React Native CLI 使用选项 --configuration 和 Release 值来执行此操作(例如 react-native run-ios --configuration Release)。

Then you can generate your archive as usual.然后你可以像往常一样生成你的档案。

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

i cannot comment on the above answer, it is correct but you need to start with the following command in order for it to work:我无法对上述答案发表评论,这是正确的,但您需要从以下命令开始才能使其正常工作:

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

the difference is 'ios' instead of 'iOS'区别在于“ios”而不是“iOS”

if not it will give the following error:如果不是,它会给出以下错误:

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

iOS IOS

  1. Open iOS project with Xcode using the following simple command from your root folder.使用根文件夹中的以下简单命令,使用 Xcode 打开 iOS 项目。

     xed ./ios
  2. Now paste the following command in terminal现在将以下命令粘贴到终端中

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

    在此处输入图片说明

  3. Edit the scheme from Xcode like this:像这样从 Xcode 编辑方案:

    Product -> Scheme -> Edit Scheme产品 -> 方案 -> 编辑方案

    在此处输入图片说明

    Edit scheme to release编辑方案发布

    在此处输入图片说明

Now you have a stand-alone Xcode project and ready to build/release like native Xcode project.现在您有了一个独立的 Xcode 项目,并准备像原生 Xcode 项目一样构建/发布。

Ans From: https://medium.com/better-programming/create-ipa-and-apk-from-react-native-72fe53c6a8db来自: 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