4

I'm trying to determine if the app is running in the simulator or on the hardware (Apple iPhone) device.

Various answers are all suggesting that I do the following:

bool isSimulator = MonoTouch.ObjCRuntime.Runtime.Arch ==
    MonoTouch.ObjCRuntime.Arch.SIMULATOR;

which I've added to my iOS app AppDelegate.cs file. But it does compile - I'm missing a namespace or assembly.

Here's a pic of the FULL method (with the colour coding showing it cannot find the static property):

enter image description here

halfer
  • 19,824
  • 17
  • 99
  • 186
Pure.Krome
  • 84,693
  • 113
  • 396
  • 647

2 Answers2

7

Using Clause:

using ObjCRuntime;

Code:

bool isSimulator = Runtime.Arch == Arch.SIMULATOR;

FYI: The MonoTouch namespace is deprecated (~2012) and has been broken up into multiple namespaces within the "Xamarin.iOS" product.

SushiHangover
  • 73,120
  • 10
  • 106
  • 165
  • You don't actually need the using ObjCRuntime if you are specifying it in the code. Correct on the MonoTouch namespace not been needed anymore. – Adam Jan 25 '16 at 04:49
0

Alternative approach that uses the UIDevice.CurrentDevice information:

public static class IosHelper
{
    public static bool IsSimulator {
        get {
            return UIDevice.CurrentDevice.Model.EndsWith("Simulator") || UIDevice.CurrentDevice.Name.EndsWith("Simulator");
        }
    }
}

Derived from this answer.

Community
  • 1
  • 1
matthewrdev
  • 11,930
  • 5
  • 52
  • 64