Requirement Typing
The development of iOS project, sometimes due to the needs of the project, often have a test environment, release environment, enterprise environment, such as configuration of different environments.
This in the code there will be a lot of if-else judgment processing logic, and often because the project emergency line caused a parameter forgot to modify configuration, resulting in production accidents, this problem has been more puzzling developers, resulting in the development of the program is not strong. Solution
It is found that Apple provides a unified configuration scheme for different environments, and here is a demo I wrote to configure different development environments. 1 First create a single View application, generate a PCH file, and configure the PCH file path in build setting, my project configuration path is $ (srcroot)/autobuildconfigset-demo/ AUTOBUILDCONFIGSET-DEMO.PCH
2 Add configuration Settings file name to Enterprise
3 Repeat step 2 to create the file structure as follows
4 Add Enterprise compilation mode to configurations under Project
5 Setting the Compile mode corresponds to the configuration settings file we created, as shown in the following figure
6 under Targets search macros the following figure
7 Add the set compilation parameters to the corresponding mode.
Debug_version=1
enterprise_version=1
release_version=1
Used to determine the schema of various compiled macros in a PCH file, as shown in the following figure 7,8,9
8 PCH folder to add the following content
Test environment
#ifdef debug_version
#define BASE_URL_STR @ "http://www.baidu.com/"
//Enterprise Environment
#elif defined ( enterprise_version)
#define BASE_URL_STR @ "http://www.google.com/"
//appstore environment
#elif defined (release _version)
#define BASE_URL_STR @ "http://www.sina.com/"
9 Add print log as follows
10 The compilation mode of the compiled schema is adjusted to Enterprise mode
11 View Print Log
IOS Packaged test release environment configuration - medium
IOS Packaged test release environment configuration - Next
GitHub Demo link address welcome star, a lot of encouragement