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):
using ObjCRuntime;
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.
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 .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.