Unable to determine if Xamarin Forms application is running in the simulator or on the device

I am trying to determine if the application is running in a simulator or on a hardware device (Apple iPhone).

Various answers suggest that I do the following:

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

which I added to the file of AppDelegate.csmy application for iOS. But it compiles - I don't have enough namespace or assembly.

Here is a pic of the FULL method (color-coded showing that it cannot find the static property):

enter image description here

+4
source share
2 answers

Using suggestion:

using ObjCRuntime;

Code:

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

FYI: MonoTouch (~ 2012) "Xamarin.iOS".

+7

, UIDevice.CurrentDevice:

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

.

0

Source: https://habr.com/ru/post/1625769/


All Articles