利用Build Configuration 配置iOS項目多個環(huán)境

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

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內(nèi)容