1.一般項目環(huán)境結(jié)構(gòu)為
|?———————————— |------------------|
|?????????? Scheme ? ? ? ? ? ? ? ? ? ?|?? Configurations |
| -------------------------- ? ? ? |------------------|
|????? XXXXProjectTest ? ? ? ? ? |????? Debug?????? |
| ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?|------------------|
| ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?|????? Release???? |
|?———————————— |------------------|
|????? XXXXProjectAppStore?? |????? Debug?????? |
| ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? |------------------|
| ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? |????? Release???? |
|?———————————— |------------------|
|????? XXXXProjectUAT ? ? ? ? ? |????? Debug?????? |
| ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?|------------------|
| ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?|????? Release???? |
|?————————————?- |—————————|
2.新建Build configuration
在project -> info 目錄下,Duplicate 新 configuration。
如果項目中用到了 cocoapods 則需要在建完之后執(zhí)行一下 pod install 命令。
3.新建scheme
我們需要為新的configuration新建對應的scheme:
新建完之后要為scheme配置對應的configuration :
配置好后要將新建的scheme共享出去:
4.配置Images.xcassets
在Images.xcassets里面新建多個AppIcon用來區(qū)分不同的變量:
添加好后在targets -> Build Setting -> Asset Catalog ?App Icon Set Name 設(shè)置對應的AppIcon :
5.配置和獲取環(huán)境變量
在project -> Build Setting -> Apple Preprocessing里面配置:
注意:如果是Swift則需在 TAGETS -> Build Settng -> Active compilation Conditions里面配置:
設(shè)置好標識符之后,我們可以在代碼里添加如下:
#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.設(shè)置對應的Bundle?identifier
在targets -> Build Setting -> Product Bundle identifier 設(shè)置對應的ID