利用Build Configuration 配置iOS项目多个环
1.一般项目环境结构为
| ———————————— |------------------|
| Scheme | Configurations |
| -------------------------- |------------------|
| XXXXProjectTest | Debug |
| |------------------|
| | Release |
| ———————————— |------------------|
| XXXXProjectAppStore | Debug |
| |------------------|
| | Release |
| ———————————— |------------------|
| XXXXProjectUAT | Debug |
| |------------------|
| | Release |
| ———————————— - |—————————|
2.新建Build configuration
在project -> info 目录下,Duplicate 新 configuration。

如果项目中用到了 cocoapods 则需要在建完之后执行一下 pod install 命令。
3.新建scheme
我们需要为新的configuration新建对应的scheme:

新建完之后要为scheme配置对应的configuration :

配置好后要将新建的scheme共享出去:

4.配置Images.xcassets
在Images.xcassets里面新建多个AppIcon用来区分不同的变量:

添加好后在targets -> Build Setting -> Asset Catalog App Icon Set Name 设置对应的AppIcon :

5.配置和获取环境变量
在project -> Build Setting -> Apple Preprocessing里面配置:

注意:如果是Swift则需在 TAGETS -> Build Settng -> Active compilation Conditions里面配置:

设置好标识符之后,我们可以在代码里添加如下:
#ifdef DEV
#define searchURL @"http://www.baidu.com"
#define sociaURL @"weibo.com"
#elif UAT
#define searchURL @"http://www.bing.com"
#define sociaURL @"twitter.com"
#else
#define searchURL @"http://www.google.com"
#define sociaURL @"facebook.com"
#endif
6.设置对应的Bundle identifier
在targets -> Build Setting -> Product Bundle identifier 设置对应的ID
