Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to determine if the Xamarin Forms application is running in the Simulator or on the Device

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

like image 325
Pure.Krome Avatar asked Mar 13 '23 12:03

Pure.Krome


1 Answers

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.

like image 144
SushiHangover Avatar answered Apr 05 '23 22:04

SushiHangover