正文
开发中经常会用到同一个app联调不同服务器环境的情况。比如我们开发在开发环境,测试需要测试环境,还有生产环境。一般同一个app来说,都是服务器相关的地址不同,本文记录下通过Configurations 来配置多环境问题。后续更新其他方式实现。
- 使用 Configurations 配置
1.添加configuration
如图添加新的configuration

点击➕添加后出现选择

这里根据自己当前的需要进行选择,debug是调试模式,它会包含编译参数集合。
自定义命名,修改为DebugTest。如果项目用到pod可以看到下面的列表

注意点:如果项目使用了pod 建议添加后先对项目进行pod install操作。
2.增加Scheme
为新创建的configuration添加scheme.

自己定义scheme名称

3.在Build Settings 中添加自定义配置

如下图修改自定义配置项名称为APP_NAME,可以看到左边列对应的就是不同scheme右边是对应的值。

3.在info.plist中使用自定义配置

如图把Bundle name 读取值设置为自定义的App_NAME即可。
另外如果是需求不同测试环境的app同是安装到手机上可以修改Bundle identifier。如上图方式,配置后可以同是存在多个版本环境下app。一般开发中我们的profile文件是和bundle ID绑定的,所以这种直接修改的方式只能在测试的时候使用。
4.配置不同环境下的预编译

如图修改不同scheme下的预编译宏文件。保证不同scheme有唯一标识字段来区分不同的环境。


如图就可以在不同scheme下进行切换了。
总结:
配置同一个app下的多环境联调测试配置。
网友评论