Skip to content
This repository has been archived by the owner on Oct 20, 2022. It is now read-only.

Latest commit

 

History

History

environment_checks

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
id title
F4D6F2C3-0B5C-1977-00BA-E38AAB660FC3
Environment Checks

This recipe shows how to make various environment checks from your code to handle different runtime environments.

Check Simulator vs. Device

You can detect whether you are running on the simulator or device by looking up the value of the ObjCRuntime.Runtime.Arch field. If the value is ARCH.Device, you are running on the physical hardware, otherwise you are running on the simulator.

Check the iOS/tvOS Version

The iOS and tvOS operating system version can be checked like this:

if (UIDevice.CurrentDevice.CheckSystemVersion (9,0))
{
   // Code that uses features from iOS 9.0 and later
} else {
   // Code to support earlier iOS versions
}

the UIDevice class exposes other environment properties that can be checked.

Check the watchOS Version

The watchOS operating system version can be checked like this:

if (WKInterfaceDevice.CurrentDevice.CheckSystemVersion (3, 0)) {
// Code that uses features from watchOS 9.0 and later
} else {
// Code to support earlier watchOS versions
}

Check your Xamarin.iOS Version

The version of Xamarin.iOS is stored in the field ObjCRuntime.Constants.Version. This is a string, you can turn this into a Version object with code like this:

Version version = new Version (ObjCRuntime.Constants.Version);
if (version > new Version (7,0))
{
   // Code that uses features from Xamarin.iOS 7.0
}