Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect in Xcode iPhone project whether I'm building for simulator or device?

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.

like image 932
Greg Maletic Avatar asked Dec 01 '09 19:12

Greg Maletic


1 Answers

#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.

like image 63
luvieere Avatar answered Sep 30 '22 16:09

luvieere