# MoreEnvironment **Repository Path**: jianchun/MoreEnvironment ## Basic Information - **Project Name**: MoreEnvironment - **Description**: MoreEnvironment 多环境配置 - **Primary Language**: Objective-C - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2018-12-12 - **Last Updated**: 2020-12-20 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # 多环境配置方案 简介: 同一项目需要多个环境切换,比如,测试环境,生产环境,生产环境debug(由于有时候生产环境需要debug)分别命名为Debug, Release(), Release_Debug. 我们用xconfig文件来实现多环境切换 打开项目 选择当前xxxx.proj 选择info 新建一个configuration 类型为 debug 类型 在工程目录下 创建 configure文件夹 分别创建Debug.xcconfig, Release.xcconfig, Product_Debug.xcconfig配置文件, 在这些配置文件中分别存放对应的私有数据, 如:服务器地址 appkey 等等 例如: APP_DISPLAY_NAME = 测试服 APP_SERVER_IP_HOST = http:\/\/www.baidu.com:8080 同时创建common.xcconfig, 这里存放共同的数据,版本号之类的, 然后在project 的configurations 配置各自的对应xcconfig文件 如果使用了cocoa pods 需要执行 pod install 然后在plist中添加对应的key 比如: AppServerIpHost $(APP_SERVER_IP_HOST) 在代码中使用 key为 AppServerIpHost 获取plist文件中的服务器地址