I've three API
with different API Keys
and some different settings
For development or internal testing build - Development distribution outside the iOS App Store
Host
- devapi.project-name.comAPI Key
- development_keyFLEX
[1] - Enable
For client testing build - Enterprise distribution outside the iOS App Store
Host
- stgapi.project-name.comAPI Key
- enterprise_keyFLEX
- Enable
For production build - Distribution in the iOS App Store
Host
- API.project-name.comAPI key
- app_store_keyFLEX
- Disable
I'm able to manage two setting by using DEBUG
#if DEBUG
#define API_BASE_URL @"http://devapi.project-name.com/api/v1"
#define API_KEY @"development_key"
#else
#define API_BASE_URL @"http://stgapi.project-name.com/api/v1"
#define API_KEY @"enterprise_key"
#endif
// In AppDelegate.m
#if DEBUG
[[FLEXManager sharedManager] showExplorer];
#endif
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
For Enterprise distribution
#if DEBUG //debug setting #else //enterprise setting #define API_BASE_URL @"http://stgapi.project-name.com/api/v1" #define API_KEY @"enterprise_key" #endif
For App Store distribution
#if DEBUG //debug setting #else //app store setting #define API_BASE_URL @"http://api.project-name.com/api/v1" #define API_KEY @"app_store_key" #endif
I'm looking for way something like this
#ifdef DEVELOPMENT
#define API_BASE_URL @"http://devapi.project-name.com/api/v1"
#define API_KEY @"development_key"
#elif ENTERPRISE
#define API_BASE_URL @"http://stgapi.project-name.com/api/v1"
#define API_KEY @"enterprise_key"
#elif APP_STORE
#define API_BASE_URL @"http://api.project-name.com/api/v1"
#define API_KEY @"app_store_key"
#endif
Or any other?
Second Problem
Is there any way to create three build with different name without creating different target?
ProductName
- For App StoreProductName-Dev
- For Internal Development buildProductName-Stg
- For Client Testing (Enterprise) build
I've just created demo project and full visual guide based on solution give by iamnichols
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:
Create Individual Configurations
In the project (not target) settings, create (duplicate from the originals) the following configurations:
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
.Create a scheme for each environment
Instead of just having a MyApp scheme, create the following (duplicate the original):
In each scheme, use the associated Debug_* and Release_* configurations where appropriate.
Add a preprocessor macro to identify environments
Add an additional preprocessor macro to identify what environment you are building against.
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.eENV_DEV=1
,ENV_STAGING=1
andENV_PROD=1
.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:
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.
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 yourinfo.plist
set the value of the Bundle Display Name to$(MYAPP_DISPLAY_NAME)
.