Writing in the front

About Multiple Environments

  • Project: contains all the information about the Project — all the code, resource files (workSpace includes multiple projects)
  • Target: How the specified code and resource files are built
  • Scheme: Configures the environment for the specified Target

More than one, the Target

Target is a working person. Whereas Scheme is the boss (environment configuration), Target works for whoever pays the most (which environment is specified)

1.Duplicate Target

2. Use a unified name

3. Modify BundleId and AppIcon

You can tell the two apartTargetthe

4. Use macro definitions to distinguish targets

5. Swift configuration

The Swift configuration is slightly different in that macros are precompiled with Other Swift Flags

  1. Start by creating the Swift file and create the bridge file
  2. Add the Swift file to the compile list
  3. Specifies the Swift language version and the bridge file
  4. OC and Swift can be mixed at this point
  5. Use predefined macros (unlike OC, Swift requires the form “-d XXX”, which splits into two lines by hitting Enter)

Actually,More than the TargetAlso usedSchemeConfiguration – As mentioned earlier, which configuration to use depends on the choiceSchemeThe correspondingTarget

Multi-target configuration with multiple environments is fine for us, but it generates multiple info.plist files and is cumbersome — you have to switch back and forth between targets to configure different parameters. Fortunately, there are other configuration solutions

Second, the Scheme

This scheme is similar to the multi-target scheme in that the requirements are achieved through user-defined parameters. It is better to call it multi-configuration than multi-scheme

1. The new Configuration

2. The new Scheme

3. The corresponding Configuration Scheme

4. Add custom configurations

5. In a multi-scheme Scheme, BundleId and AppIcon can also be modified

Anything in BuildSettings can be configured in multiple environments

6. Use the info.plist file for mapping

This allows for multi-environment configuration by switching Scheme, but the custom configuration is still a bit complicated

More than three, Xcconfig

1. New Xcconfig

The best way to name it isConfig- Project name. Environment Configuration. Xcconfig(Refer to the xcConfig file integrated by Cocoapods.)

2.Configuration Select the CORRESPONDING Xcconfig

The entry above is configurationProjectThe following entry is configurationTarget

3. Configure the Xcconfig file

Some variable configurations do not work in BuildSettings, such as PRODUCT_BUNDLE_IDENTIFIER

4. Configure the info.plist file for mapping

The configuration is the same as plan 2The info. The filemapping

The xcConfig file is essentially the option to configure BuildSetting — the Xcode Build Settings website details the variables

Xcconfig conflicts

1. The Pods – config conflict

Often we do it in multiple environmentspodfileAfter the configuration, the terminal displays the following warning and the project cannot runThe project has been configuredconfig.Pods-configMay not take effect “– To resolve this warning, and also to run the project properly, we need to customize itXcconfigIn-file referencePods-config

Add Target Support Files/ PODs-FXdemo/PODs-fxDemo.release.xcconfig to the xcConfig file as prompted. This alone does not refer to the corresponding Pods-config, which should be imported as follows according to the directory:

#include "Pods/Target Support Files/ PODs-fxdemo/PODs-fxDemo.debug.xcconfig "ConfigurationString = This is the development environmentCopy the code

Refer to PODs-config in all environment configurations, and terminal warnings are eliminated

2. Xcconfig inheritance

The above reference operation is not enough, the reference only refers to the original configuration, if overwritten will be overwrittenSo we need to use Xcode’s built-in$(inherited)Field to inherit (Pods-configIt works the same way.)

#include "Pods/Target Support Files/ PODs-fxdemo/PODs-fxDemo.debug.xcconfig "ConfigurationString = This is the development environment OTHER_LDFLAGS =  $(inherited) -framework "FXSDK"Copy the code

3. Add Other Linker Flags

inreferenceandinheritanceAnd then after that, you can go toBuildSettingsThe new link

Xcconfig expansion

  • Include can use absolute/relative paths
// Absolute path #include "Pods/Target Support Files/ PODs-fxdemo/PODs-fxdemo.debug.xcconfig "// relative path #include "/Users/felix/Desktop/FXDemo/Pods/Target Support Files/Pods-FXDemo/Pods-FXDemo.debug.xcconfig"Copy the code
  • Url definition can be implemented using intermediate quantities (using variables can be usedThe $()orThe ${})
diagonal = /
ConfigurationString = https:${diagonal}/baidu.com
Copy the code
  • Use environment variables to limit the scenarios in effect
OTHER_LDFLAGS[config= debug][SDK =iphonesimulator*][arch=x86_64] = -framework "FXSDK"Copy the code

Write in the back

In fact, multi-environment configuration is more than just Target, Scheme, and Xcconfig. You need to understand their respective functions and use them together to better meet the requirements of multi-environment configuration