WechatIMG74.png
完成后可以看到项目已经有多个 Configuration了。
2.pod项目需要做如下操作
项目里面用了Pod,打开配置是会看到如下信息
WechatIMG75.png
需要执行
pod install
这时候pod安装完成之后会自动生成xcconfig文件,里面有一些pod的配置
3.新建Scheme
新建的Scheme,在运行的时候可以选择我们运行的环境,如:Debug、QA、UAT、Released等
WeChat122fc3f32976a80c384415413b5dacd7.png
然后点击选择他的运行环境,在我们新添加的项目中改变Run模式和Archive模式,把他们都改为Debug。
WechatIMG76.png
4. 新建User-defined Build Settings
在Project的Build Settings中添加Add User-Defined Setting
我们知道,在plist中我们可以通过$(PRODUCT_BUNDLE_IDENTIFIER)来查找Bundle identifier,我们可以自己设置路径,然他查找Bundle identifier
WechatIMG77.png
在plist文件中修改value值便于匹配自定义的值
WechatIMG79 1.png
5.配置和获取环境变量
找到Preprocessor Macros,可以加一些环境变量的宏定义来标识符,根据不同的环境预先制定不同定义的宏用于在网络库上区分不同环境。
WechatIMG80.png
6.配合网路库区分不同环境
NSString *urlString = [request requestURL];
NSDictionary *params = [self constructRequestParams:request]; // 构造参数
urlString = [NSString stringWithFormat:@"%@%@",BaseURLString, urlString];
if ([CCNetworkConfig sharedInstance].isShowDebugLog)
{
NSLog(@"\n\n---------------request start 发起请求报文---------------------------\n\n 请求的地址为\n :%@\n 加密前请求报文是:\n %@\n----------------request end 发起请求报文------------------\n\n",urlString,params);
}
AFHTTPSessionManager *manager = [self sharedHttpSessionManager];
manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json",@"text/html", nil];
manager.responseSerializer = [AFHTTPResponseSerializer serializer];
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
__weak typeof(self) weakSelf = self;
NSURLSessionDataTask *task = [manager POST:urlString
parameters:params
progress:^(NSProgress * _Nonnull downloadProgress){ }
success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject)
{
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
NSString *resopnseString = [[NSString alloc] initWithData:responseObject
encoding:NSUTF8StringEncoding];
NSData *jsonData = [resopnseString dataUsingEncoding:NSUTF8StringEncoding];
NSDictionary *content = [NSJSONSerialization JSONObjectWithData:jsonData
options:NSJSONReadingMutableContainers
error:nil];
//访问接口地址
//@"https://app.xxxxx.com/"//正式环境
//@"http://dev.xxxxx.com/"//开发环境
//@"https://qa.xxxxx.com/"//测试环境
#define CCInfoPlistPath [[NSBundle mainBundle] pathForResource:@"Info" ofType:@"plist"]
#define CCInfoPlistPathGetDic [NSMutableDictionary dictionaryWithContentsOfFile:CCInfoPlistPath]
#define CCInfoPlistGetValue(key) [CCInfoPlistPathGetDic objectForKey:key]
#define BaseURLString CCInfoPlistGetValue(@"App Request Base URL")
WechatIMG81.png

评论列表