iOS realizes the complete process of multi-scheme switching environment


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
Please add a picture description
, select the Duplicate “Debug” Configuration option in the tab,
Please add a picture description
and name the newly added configuration.
Please add a picture description
I named it KKK-F1 here.
Please add a picture description

Two, add scheme

Click the existing scheme name to display the sheme operation panel, select New scheme,
as shown in the figure:
Please add a picture description

A pop-up window pops up to name the scheme
Please add a picture description

For convenience, I have the same name as the newly added configuration here, and both use KKK-F1
Please add a picture description

3. Set the corresponding relationship between scheme and configuration

Select the scheme we want to set
Please add a picture description

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
Please add a picture description

Set the Build Configuration in run, test, profile, analyze, and archive respectively

Please add a picture description

Please add a picture description

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

Please add a picture description

The contents of the two configuration files are as follows
Please add a picture description
Please add a picture description

The actual location of the configuration file is placed in a folder with the same name as the project
Please add a picture description

Please add a picture description

Remove the files of the KKK-F1 environment in the copy bundle resources (not removed in the project)
Please add a picture description

Please add a picture description

Set up the compilation script and use different local configuration files in different configurations
Click "+" in build phases
Please add a picture description

Select new run script phasePlease add a picture description

Set the script name (custom), and add the running script
Please add a picture description
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}/"

Please add a picture description

Five, run

Please add a picture description
Please add a picture description

Above, we have achieved the purpose of switching the environment by switching the scheme

Guess you like

Origin blog.csdn.net/LIUXIAOXIAOBO/article/details/131358296