Article directory
Preface
We all need to switch environments during development. Many small partners implement switching environments through macro definitions
. This method is not elegant, and it can also cause the problem of slow compilation every time switching environments.
Therefore, here we Switch the environment by switching the scheme
1. Add configuration
Select project -> info-Configuration, click Add under confutation, as shown in
the figure
, select the Duplicate “Debug” Configuration option in the tab,
and name the newly added configuration.
I named it KKK-F1 here.
Two, add scheme
Click the existing scheme name to display the sheme operation panel, select New scheme,
as shown in the figure:
A pop-up window pops up to name the scheme
For convenience, I have the same name as the newly added configuration here, and both use KKK-F1
3. Set the corresponding relationship between scheme and configuration
Select the scheme we want to set
After selecting, click scheme again, and a small pop-up window will pop up, we click Edit Scheme to edit the corresponding relationship between scheme and configuration
Set the Build Configuration in run, test, profile, analyze, and archive respectively
Here, the Build Configuration of scheme KKK-F1 is set to KKK-F1
Fourth, the local configuration file
Here we configure different environment domain names through the local plist file
Add a configuration resource folder to the project
The contents of the two configuration files are as follows
The actual location of the configuration file is placed in a folder with the same name as the project
Remove the files of the KKK-F1 environment in the copy bundle resources (not removed in the project)
Set up the compilation script and use different local configuration files in different configurations
Click "+" in build phases
Select new run script phase
Set the script name (custom), and add the running script
I set the name here
Copy Configuration FIles
screenplay
RESOURCE_PATH=${SRCROOT}/${PRODUCT_NAME}/Configuration/${CONFIGURATION}
BUILD_APP_DIR=${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.app
echo "Copying all files under ${RESOURCE_PATH} to ${BUILD_APP_DIR}"
cp -v "${RESOURCE_PATH}/"* "${BUILD_APP_DIR}/"
Five, run
Above, we have achieved the purpose of switching the environment by switching the scheme