8

Does anyone know the compiler directive I'd use in MonoTouch to see if I'm running in the iPhone simulator? Can't find any info anywhere.

Thanks!

Rolf Bjarne Kvinge
  • 19,253
  • 2
  • 42
  • 86
SomaMan
  • 4,127
  • 1
  • 34
  • 45

1 Answers1

12

There is no compiler directive (conditional compilation symbol) to determine if you're running in the iPhone simulator or on a device.

You can however determine it at runtime, using this code:

using ObjCRuntime;
static bool InSimulator ()
{
    return Runtime.Arch == Arch.SIMULATOR;
}

This is from here: http://docs.xamarin.com/ios/recipes/General/Projects/Environment_Checks

Rolf Bjarne Kvinge
  • 19,253
  • 2
  • 42
  • 86
  • 2
    If you need to, you can add your own compile time symbol in the Compiler options on each project settings – Stuart Jun 07 '12 at 11:28
  • It is now in Xamarin.iOS: `static bool InSimulator () { return ObjCRuntime.Runtime.Arch == ObjCRuntime.Arch.SIMULATOR; }` https://developer.xamarin.com/api/type/ObjCRuntime.Arch/ – Ben Butzer Oct 26 '16 at 18:18