views:

266

answers:

1

Is there any way I can conditionally compile in my app based upon whether I'm building for the simulator or the device? (My app hooks to an external server: if I'm running on the device, I want to connect to localhost; if I'm running on the device, I want to go to my production server.)

I'm looking for some #ifdef variable I can detect, or even something at runtime...doesn't matter.

Thanks.

+3  A: 
#if !(TARGET_IPHONE_SIMULATOR)

or, alternatively,

#if (TARGET_OS_IPHONE)

will tell you if you're running on the device. In order for it to work, you must

#include "TargetConditionals.h"

file that you can find here.

luvieere
Thanks...that seems to work.Any way to find out what else is defined in "TargetConditionals.h"? I can't find the file anywhere...
Greg Maletic
Correction...your second example (TARGET_OS_IPHONE) always succeeds, provided, of course, you're doing iPhone development. Your first example, TARGET_IPHONE_SIMULATOR, is what I'm looking for, and that only succeeds if you're running on the simulator (vs. the device.)
Greg Maletic
Edited with a link to the file.
luvieere
I've never included that file and TARGET_IPHONE_SIMULATOR always seems to work - it could already be included by the foundation.
Kendall Helmstetter Gelner