RameshIos
RameshIos

Reputation: 301

Objective c iphone - How to differentiate the production build with qa/debug testng build

My actual requirement is

I want to do some changes in some values, these values are different for different builds,

Like say for example:

We have used Parse.com frame work and Flurry integration in our application. We need to provide some keys for these parse / flurry integrations

as

 [Parse setApplicationId:@"6Z8Antqqf4u5TZFbUtzePuoPnOjqgkFHsQXmVtGW" clientKey:@"SiDnoJsvHjMBdaFw3QRpm2mvVblJsdYYkWHBL8hR"];

Here i want to use different keys for different types of builds to avoid effecting the original production build.

So how can i differentiate

Production build (clint build / appstore build) AdHoc build (Internal distributed build like Testflight/appearean) QA/Debug build (internal testing while implemented)

Upvotes: 0

Views: 205

Answers (2)

cohen72
cohen72

Reputation: 2988

Preprocessing macros work, however you could use a more reliable and organized way of doing it, allowing you to keep all debug, adhoc, and production environment variables stored away it their own respective places.

That would be to create a separate target for each environment and assign a different .m file for each target.

For example, to create a debug environment:

1) Create (by duplicating your current target) a new "debug" target.

2) Create a "configs" file, lets call it configs.m/.h

3) Add to your configs.m file all your app keys for each of your service Parse, Facebook, Flurry etc.

4) duplicate the file, and call it configs_debug.m. (choose "debug" target as its target).

5) Ensure each file points to its correct target by clicking on it and checking its "target membership" under identity and type in the Utilities window on the right. configs.m should point to "production" target and configs_debug.m should point to "dev" target.

Each file will look essentially the same in the .m, only change you need to make is the value of the key.

Configs.h

extern NSString * const PARSE_APP_KEY;
@interface Configs : NSObject
@end


Configs.m (points to target "production")

#import "Configs.h" 

NSString * const PARSE_APP_KEY = @"yyyyyyyyyy";

@implementation Configs

@end


Configs_debug.m (points to target "debug")

#import "Configs.h"

NSString * const PARSE_APP_KEY = @"xxxxxxxxx";

@implementation Configs

@end

Upvotes: 0

Simon
Simon

Reputation: 1394

You can use preprocessing macros. Navigate to your target, and go to build settings (make sure all is selected, and not basic):

enter image description here

Example use:

#ifdef DEBUG
        NSString* appKey = @"DEBUG_KEY";
#else
        NSString* appKey = [config valueForKey:@"AppKey"];
#endif

Upvotes: 1

Related Questions