ios 如何为 React Native 构建 .IPA?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/35476349/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 08:32:47  来源:igfitidea点击:

How to build .IPA for React Native?

iosreact-native

提问by sodik

I come to React Native development without previous experience of iOS development. I want to build release .IPA file - ideally from command line but the official documentation Running On Deviceis very brief.

我是在没有 iOS 开发经验的情况下来到 React Native 开发的。我想构建发行版 .IPA 文件 - 最好是从命令行,但官方文档Running On Device非常简短。

I was able to deploy application on my iPhone manually via XCode but still I can't find any "release IPA" file. I have updated my code with #ifdef DEBUGdirectives to make it more generic.

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

Is there a way to build application in release mode only via commandline? If no, what is "the official" way to generate RN application?

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

I am currently using RN 0.20.

我目前正在使用 RN 0.20。

回答by G. Hamaide

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 并根据你想要的版本按照步骤操作

回答by Diego Mello

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 (e.g. 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

回答by Hanane

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;
  ^