Currently in React-Native, according to the documentation , in order to create an iOS application for production, you need to:
- change your schema to
Release - modify your
AppDelegate.m to download the correct package - change
Info.pList for ATS
This is a strong violation of 12 configuration recommendations , and this leads to errors that occur during the continuous integration process.
RN provides neither a strategy nor a command to know the configuration environment in JS code, which led to the existence of the react-native-config package, which works fine but not perfect (Xcode is not fully supported) .
Why is that? Is it because there are so few RN applications currently in production that nobody cares? Can we work better than react-native-config so that the steps above are not required? I need a command line that archives my application the same way I can run cd android && ./gradlew assembleRelease without changing anything in my configuration.
EDIT:
Fastlane simplifies deployment with the gym command (thanks to Daniel Basedow). Apparently, Xcode’s philosophy is to call “schema” environments, only you cannot store variables in them or know which circuit you use in your code ... Anyway, David C. Hess found a great way to export the name of your schema is in Info.pList , and then in your Objective-C code, which means that now I can choose my package according to the current schema and not touch my code.
Here is my code: NSString *schemeName = [[[NSBundle mainBundle] infoDictionary] valueForKey:@"SchemeName"]; if ([schemeName isEqualToString:@"scheme1"]) { jsCodeLocation = [NSURL URLWithString:@"http://localhost:8081/index.ios.bundle?platform=ios&dev=true"]; } else if ([schemeName isEqualToString:@"scheme2"]) { jsCodeLocation = [NSURL URLWithString:@"http://<my_local_ip_address>:8081/index.ios.bundle?platform=ios&dev=true"]; } else if ([schemeName isEqualToString:@"scheme3"]) { jsCodeLocation = [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"]; } NSString *schemeName = [[[NSBundle mainBundle] infoDictionary] valueForKey:@"SchemeName"]; if ([schemeName isEqualToString:@"scheme1"]) { jsCodeLocation = [NSURL URLWithString:@"http://localhost:8081/index.ios.bundle?platform=ios&dev=true"]; } else if ([schemeName isEqualToString:@"scheme2"]) { jsCodeLocation = [NSURL URLWithString:@"http://<my_local_ip_address>:8081/index.ios.bundle?platform=ios&dev=true"]; } else if ([schemeName isEqualToString:@"scheme3"]) { jsCodeLocation = [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"]; }
Now my problem is: I also want to know which circuit I'm running in my JS code. react-native-config path is self-described as hacky and too complicated, given the fact that the information is already in my Objective-C code. Is there a way to reduce this information to my JS code?
Just knowing which circuit I'm running is not as good as being able to set environment variables, but at least I can only switch between environments by changing my circuit.
EDIT 2:
I managed to export my schema to my JS code. I created a cocoa touch class with the following code:
// RNScheme.h #import <Foundation/Foundation.h>
and then in my JS code:
import {NativeModules} from 'react-native' let scheme = NativeModules.RNScheme.scheme_name
EDIT 3:
There is actually a different way than using circuits. You can create new “configurations” (“Release” and “Debug” are called configurations) with the following steps (thanks to CodePush ):
Open your Xcode project and select your project in the Project navigator window
Make sure the node project is selected and not one of your goals
Select the Information tab
Click the + button in the "Configurations" section and select which configuration you want to duplicate.

Then you can define keys with different values ​​according to your configuration.
Choose the goal of your application
Choose build settings
Go to the User-Defined section (at the bottom of the scroll area)
You can define constants with a different value according to your configuration (e.g. API_ENDPOINT )
You can then reference this value in the Info.pList file:
Open the Info.pList file
Create a new value and give it a name ( ApiEndpoint )
Give it a value of $(API_ENDPOINT) or any other name that you pointed to a constant
Now you can reference this value in your code using the code I gave you during the second edit of this question.
You can create one circuit for each configuration to quickly switch from one to another or change the assembly configuration each time (the option presses the start button).