我有三个 API ,包含不同的 API密钥和一些不同的设置
I've three APIwith different API Keys and some different settings
-
用于开发或内部测试构建 - iOS App Store外的开发分发
For development or internal testing build - Development distribution outside the iOS App Store
- 主机 - devapi.project-name
- API键 - development_key
- FLEX [ 1 ] - 启用
- Host - devapi.project-name
- API Key - development_key
- FLEX[1] - Enable
用于客户端测试构建 - iOS App Store外的企业分发
For client testing build - Enterprise distribution outside the iOS App Store
- 主机 - stgapi.project-name
- API密钥 - enterprise_key
- FLEX - 启用
- Host - stgapi.project-name
- API Key - enterprise_key
- FLEX - Enable
用于生产构建 - 分发在iOS App Store中
For production build - Distribution in the iOS App Store
- 主机 - api.project-name
- API k ey - app_store_key
- FLEX - 禁用
- Host - api.project-name
- API key - app_store_key
- FLEX - Disable
我可以使用 DEBUG来管理两个设置
#if DEBUG #define API_BASE_URL @"devapi.project-name/api/v1" #define API_KEY @"development_key" #else #define API_BASE_URL @"stgapi.project-name/api/v1" #define API_KEY @"enterprise_key" #endif // In AppDelegate.m #if DEBUG [[FLEXManager sharedManager] showExplorer]; #endif
但第一个问题是企业分发(适用于客户端测试)和iOS App Store分发(生产)构建,适用于Enterprise和App 商店分发每次需要更改代码
But first problem is Enterprise distribution (for client testing) and iOS App Store distribution (production) build, for Enterprise and App Store distribution every time need to change code
-
企业分销
#if DEBUG //debug setting #else //enterprise setting #define API_BASE_URL @"stgapi.project-name/api/v1" #define API_KEY @"enterprise_key" #endif -
对于App Store分发
#if DEBUG //debug setting #else //app store setting #define API_BASE_URL @"api.project-name/api/v1" #define API_KEY @"app_store_key" #endif - ProductName - 适用于App Store
- ProductName-Dev - 用于内部开发构建
- ProductName-Stg - 对于客户测试(企业)构建
- ProductName - For App Store
- ProductName-Dev - For Internal Development build
- ProductName-Stg - For Client Testing (Enterprise) build
- Debug_Dev
- Debug_Staging
- Debug_Prod
- Release_Dev
- Release_Staging
- Release_Prod
- Debug_Dev
- Debug_Staging
- Debug_Prod
- Release_Dev
- Release_Staging
- Release_Prod
- MyApp_Dev
- MyApp_Staging
- MyApp_Prod
我正在找东西像这样
#ifdef DEVELOPMENT #define API_BASE_URL @"devapi.project-name/api/v1" #define API_KEY @"development_key" #elif ENTERPRISE #define API_BASE_URL @"stgapi.project-name/api/v1" #define API_KEY @"enterprise_key" #elif APP_STORE #define API_BASE_URL @"api.project-name/api/v1" #define API_KEY @"app_store_key" #endif或其他任何?
第二个问题
Second Problem
有没有办法用不同的名称创建三个版本创建不同的目标?
Is there any way to create three build with different name without creating different target?
我'我刚刚创建了演示项目a基于 iamnichols 提供的解决方案的完整视觉指南
I've just created demo project and full visual guide based on solution give by iamnichols
推荐答案调试和发布版本之间的区别在于,一个是存档并导出,而另一个是通过调试器中的Xcode本地运行的。您可能会发现您有时希望在调试器中运行生产或暂存构建,但是通过 #ifdef DEBUG 拆分东西,您可能会遇到问题。
The difference between a debug and a release build is that one is archived off and exported but the other is run locally via Xcode in the debugger. You might find that you want to sometimes run the production or staging build in the debugger too but by splitting stuff out by #ifdef DEBUG, you are probably going to run into issues.
这是我所做的简化版本:
This is a simplified version of what I do:
在项目(非目标)设置中,创建(从原件复制)以下配置:
In the project (not target) settings, create (duplicate from the originals) the following configurations:
请注意,如果您使用Cocoapods,则需要将配置设置回none,删除项目中Pods文件夹的内容( Not the Pods project )并重新运行 pod install 。
Note that if you use Cocoapods then you will need to set the configurations back to none, delete the contents of the Pods folder in your project (Not the Pods project) and re-run pod install.
不要只有MyApp方案,而是创建以下内容(复制原件):
Instead of just having a MyApp scheme, create the following (duplicate the original):
在每个方案中,在适当的地方使用相关的Debug_ *和Release_ *配置。
In each scheme, use the associated Debug_* and Release_* configurations where appropriate.
添加一个额外的预处理器宏来识别您正在构建的环境。
Add an additional preprocessor macro to identify what environment you are building against.
在项目构建设置中,单击+并添加用户定义的构建设置,并将其称为 MYAPP_ENVIRONMENT 。然后,对于每个不同的环境组,为每个环境添加不同的预处理器宏。即 ENV_DEV = 1 , ENV_STAGING = 1 和 ENV_PROD = 1 。
In the project build settings, click the + and add a user defined build setting and call it something like MYAPP_ENVIRONMENT. Then, for each different group of environments, add a different preprocessor macro to each one. i.e ENV_DEV=1, ENV_STAGING=1 and ENV_PROD=1.
然后,在c预处理器宏中(再次在项目级别而不是目标级别)使用 $添加此新的MYAPP_ENVIRONMENT设置( MYAPP_ENVIRONMENT)。
Then, in the c preprocessor macros (again on a project level and not the target level) add this new MYAPP_ENVIRONMENT setting using $(MYAPP_ENVIRONMENT).
这样,您就可以确定您正在构建的环境,如下所示:
This way, you can then determine what environment you are building against like so:
#ifdef ENV_DEV NSString * const MyAppAPIBaseURL = @"api-dev.myapp/"; #elif ENV_SAGING NSString * const MyAppAPIBaseURL = @"api-staging.myapp/"; #elif ENV_PROD NSString * const MyAppAPIBaseURL = @"api.myapp/"; #endif这可能需要很多东西,但请告诉我你是怎么做的。
It's probably a lot to take in but let me know how you get on.
然后,您还可以创建不同的用户定义构建设置来执行不同的操作,例如更改应用的显示名称。
You can then also create different user defined build settings to do different things, like change the display name of your app.
您可以通过创建一个名为 MYAPP_DISPLAY_NAME 的新设置来完成此操作,例如,为每个配置设置正确的名称然后在 info.plist 中将Bundle Display Name的值设置为 $(MYAPP_DISPLAY_NAME)。
You could do this by creating a new setting called MYAPP_DISPLAY_NAME for example, set the correct name for each configuration and then in your info.plist set the value of the Bundle Display Name to $(MYAPP_DISPLAY_NAME).
更多推荐
iOS:使用不同设置和名称管理开发,测试和生产构建的最佳方式
发布评论