Multi-environment configuration
- Project: Contains all the code, resource files, and information for the Project.
- Target: Specifies how the code and resource files are built.
- Scheme: specifies the environment configuration for the Target.
throughpreprocesor macro
To configure multiple environments
Make decisions based on macros in the code to achieve multi-environment configuration
throughuser_defined
+Info.plist
+ a singleTarget
To configure multiple environments
chooseDebug
The environmentSame way to chooseRelease
Environment is running
throughuser_defined
+Info.plist
More than +Target
To configure multiple environments
New constructionTargetDemo
Is created in the projecttarget
namedTargetDemo2
Change the plist file name to targetDemo2-info.plist
You can see that different targets can set their own App Name, Bundle ID, Icon, and so on
If the two targets are set to the same Bundle Id then they can be considered different environments of the same App, such as Dev and Release
If the two targets have different Bundle ids, then they are completely different apps
Here we demonstrate the useTargetDemo
configurationDebug
Environment, useTargetDemo1
configurationRelease
Environment, in the creationTarget
The system also created the correspondingScheme
The selectedTargetDemo
chooseDebug
modelThe selectedTargetDemo1
chooseRelease
model
Because we’ve already configured itHOST_URL
Run respectively
When creating a Target, the system creates the corresponding Scheme for us. Therefore, we can not create multiple targets, but create multiple schemes to implement multiple environment configuration
throughuser_defined
+Info.plist
More than +Scheme
To configure multiple environments
chooseEdit Scheme
To configure
Again, I have to configure itHOST_URL
The first configurationTargetDemo
forDebug
The environment
Configure TargetDemo1 as the Release environment
Select respectivelyTargetDemo
andTargetDemo1
run
throughuser_defined
+Info.plist
+Xconfig
To configure multiple environments
You can deleteTarget
Configuration of theuser_defined
Create a folder namedxconfig
, respectivelyDebug
andRelease
The configuration file of the schema is named asFolder name -Target name. Model name
I’m going to have folders called,xconfig-TargetDemo.debug.xconfig
andxconfig-TargetDemo.release.xconfig
, respectively
Enter the content separately
Choose differentScheme
run
Go to theTargetDemo
The correspondingBuilding Settings
Check, finduser_defined
Automatically generatedHOST_URL
These are just two different ways of configuring files and visualizing them
Summary of configuration modes in multiple environments
- Use precompiled macros to make environment judgments in your code
- through
User-Defined
+Info.plist
Way to configure- Using a single
Target
And a singleScheme
, which requires each run to modifyScheme
The environment - The use of multiple
Scheme
, eachScheme
It corresponds to an environment
- Using a single
xconfig
Is to configure theUser-Defined
In another way- more
Target
It’s more like multiple apps, and this way of configuring multiple environments is overkill
Configuration conflicts
Create a new project and execute the commands separately in the root directorypod init
andpod install
Open the project to see that two configuration files are automatically generated
This is already configured by default
But if we create our ownxconfig
Configuration files and Settings required#include
The introduction ofPod
Created configuration file
You need to either set base Configurations to Pods- targetDemo.debug.xconfig or include it in config-targetDemo.debug.xconfig
inpods
Add to fileAFNetworking
And performpod install
after
We also configure it in our own configuration fileOTHER_LDFLAGS = -framework "SDWebImage"
You need to use keywords here$(inherited)
Inherits the previous configuration
We can also be inBuilding Settings
To modify the configuration
The priorities are in descending order
- Manually modify
Building Settings
- Modify the
Basic
, which is its own configuration file - Modify the
Pod
That is, the inherited file
Reference documentation
xcodebuildsettings