oky_sabeni
oky_sabeni

Reputation: 7822

How do I know if objective C code is running in iOS simulator?

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.

Upvotes: 1

Views: 942

Answers (1)

SomeGuy
SomeGuy

Reputation: 9700

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

Upvotes: 2

Related Questions