1

I've tried

#ifdef TARGET_IPHONE_SIMULATOR
  static BOOL isSimulator = YES;
#endif

But for both device and simulator, the isSimulator variable always comes out to 1.

I need a way to figure out if the code running is on iOS simulator or on a device.

oky_sabeni
  • 7,672
  • 15
  • 65
  • 89
  • 1
    As you can see on this answer http://stackoverflow.com/questions/5775420/programmatically-detect-if-app-is-being-run-on-device-or-simulator you can check where is running your app at runtime (not at compile time as you provided) like this way: #define SIM(x) if ... (by Fernando Cervantes). – stosha Apr 04 '15 at 01:18

1 Answers1

2

Your code snippet only checks if TARGET_IPHONE_SIMULATOR is defined (even if it's defined as 0)

Try checking like this instead: (the #error will simply show as a compilation error in Xcode)

#if TARGET_IPHONE_SIMULATOR
#error Simulator
#else
#error Device
#endif
SomeGuy
  • 9,670
  • 3
  • 32
  • 35