cambraca
cambraca

Reputation: 27835

Knowing if the app is running in a testing environment

Is there a way to know if the program is running in the development environment? I'm using Flurry Analytics and want to pass it a different app id, so the data doesn't get dirty with my tests during development.

What I'd like is something like this:

Boolean isDevEnv = .... (is this a test in the simulator or device,
                         OR is it a real user that downloaded the 
                         app through the app store?)
if (isDevEnv)
  [FlurryAnalytics startSession:@"firstAppId"];
else
  [FlurryAnalytics startSession:@"secondAppId"];

To be clear, this is not what I'm after, because I test using a real device as well as the simulator.

Upvotes: 1

Views: 298

Answers (4)

cambraca
cambraca

Reputation: 27835

Well, it seems this is done by default by Xode, in the Project's Build Settings, under Apple LLVM compiler 3.1 - Preprocessing (this is in Xcode 4.3.2, for future reference), a setting called DEBUG is populated with the value 1.

So, I didn't really have to do anything, just this in the code (in my case in the AppDelegate's didFinishLaunchingWithOptions method):

[FlurryAnalytics startSession:DEBUG ? @"firstAppId" : @"secondAppId"];

Upvotes: 0

Brice
Brice

Reputation: 1026

In the build settings you'll have to set flags, depending on the building env.

Then, use #ifdef and #define to set the appid.

#ifdef DEBUG
#    define APPID ...    
#else
#    define APPID ...
#endif

Upvotes: 2

0x8badf00d
0x8badf00d

Reputation: 6401

if you don't want to use DEBUG flag and DEBUG environment, create a new build configuration (duplicate Release configuration) and in the build settings Preprocessor Macros add a FlurryAnalytics flag. In your code check if(FlurryAnalytics). Create a new scheme in XCode that creates ipa using this new release build configuration.

Upvotes: 0

jrtc27
jrtc27

Reputation: 8526

In your build settings, define a new flag for the App Store release version. Then use #ifdef to determine at compile time which appid to use.

Upvotes: 0

Related Questions