Naxam.Mapbox.Platform.iOS/Extensions/UIDeviceExtensions.cs
/// <summary>
/// Gets the hardware version / model.
/// Source: https://github.com/rangav/iOSDeviceModel/blob/master/DeviceHelper.cs
/// </summary>
/// <returns>The hardware version.</returns>
Gets the hardware version / model.
Gets the hardware version / model .
public static HardwareVersion GetHardwareVersion()
        {
            var pLen = Marshal.AllocHGlobal(sizeof(int));
            sysctlbyname(HardwareProperty, IntPtr.Zero, pLen, IntPtr.Zero, 0);
            var length = Marshal.ReadInt32(pLen);
            var pStr = Marshal.AllocHGlobal(length);
            sysctlbyname(HardwareProperty, pStr, pLen, IntPtr.Zero, 0);
            var hardwareStr = Marshal.PtrToStringAnsi(pStr);
            var ret = HardwareVersion.Unknown;
            switch (hardwareStr)
            {
                case "iPhone1,1":
                    ret = HardwareVersion.iPhone;
                    break;
                case "iPhone1,2":
                    ret = HardwareVersion.iPhone3G;
                    break;
                case "iPhone2,1":
                    ret = HardwareVersion.iPhone3GS;
                    break;
                case "iPhone3,1":
                case "iPhone3,2":
                case "iPhone3,3":
                    ret = HardwareVersion.iPhone4;
                    break;
                case "iPhone4,1":
                    ret = HardwareVersion.iPhone4S;
                    break;
                case "iPhone5,1":
                case "iPhone5,2":
                    ret = HardwareVersion.iPhone5;
                    break;
                case "iPhone5,3":
                case "iPhone5,4":
                    ret = HardwareVersion.iPhone5C;
                    break;
                case "iPhone6,1":
                case "iPhone6,2":
                    ret = HardwareVersion.iPhone5S;
                    break;
                case "iPhone7,2":
                    ret = HardwareVersion.iPhone6;
                    break;
                case "iPhone7,1":
                    ret = HardwareVersion.iPhone6Plus;
                    break;
                case "iPhone8,1":
                    ret = HardwareVersion.iPhone6S;
                    break;
                case "iPhone8,2":
                    ret = HardwareVersion.iPhone6SPlus;
                    break;
                case "iPhone8,4":
                    ret = HardwareVersion.iPhoneSE;
                    break;
                case "iPhone9,1":
                case "iPhone9,3":
                    ret = HardwareVersion.iPhone7;
                    break;
                case "iPhone9,2":
                case "iPhone9,4":
                    ret = HardwareVersion.iPhone7Plus;
                    break;
                case "iPhone10,1":
                    ret = HardwareVersion.iPhone8;
                    break;
                case "iPhone10,2":
                    ret = HardwareVersion.iPhone8Plus;
                    break;
                case "iPad1,1":
                    ret = HardwareVersion.iPad;
                    break;
                case "iPad2,1":
                case "iPad2,2":
                case "iPad2,3":
                case "iPad2,4":
                    ret = HardwareVersion.iPad2;
                    break;
                case "iPad3,1":
                case "iPad3,2":
                case "iPad3,3":
                    ret = HardwareVersion.iPad3;
                    break;
                case "iPad3,4":
                case "iPad3,5":
                case "iPad3,6":
                    ret = HardwareVersion.iPad4;
                    break;
                case "iPad4,1":
                case "iPad4,2":
                case "iPad4,3":
                    ret = HardwareVersion.iPadAir;
                    break;
                case "iPad5,3":
                case "iPad5,4":
                    ret = HardwareVersion.iPadAir2;
                    break;
                case "iPad6,7":
                case "iPad6,8":
                    ret = HardwareVersion.iPadPro_12_9;
                    break;
                case "iPad6,3":
                case "iPad6,4":
                    ret = HardwareVersion.iPadPro_9_7;
                    break;
                case "iPad6,11":
                case "iPad6,12":
                    ret = HardwareVersion.iPadPro_2017;
                    break;
                case "iPad2,5":
                case "iPad2,6":
                case "iPad2,7":
                    ret = HardwareVersion.iPadMini;
                    break;
                case "iPad4,4":
                case "iPad4,5":
                case "iPad4,6":
                    ret = HardwareVersion.iPadMini2;
                    break;
                case "iPad4,7":
                case "iPad4,8":
                case "iPad4,9":
                    ret = HardwareVersion.iPadMini3;
                    break;
                case "iPad5,1":
                case "iPad5,2":
                    ret = HardwareVersion.iPadMini4;
                    break;
                case "iPod1,1":
                    ret = HardwareVersion.iPod1G;
                    break;
                case "iPod2,1":
                    ret = HardwareVersion.iPod2G;
                    break;
                case "iPod3,1":
                    ret = HardwareVersion.iPod3G;
                    break;
                case "iPod4,1":
                    ret = HardwareVersion.iPod4G;
                    break;
                case "iPod5,1":
                    ret = HardwareVersion.iPod5G;
                    break;
                case "iPod7,1":
                    ret = HardwareVersion.iPod6G;
                    break;
                case "i386":
                case "x86_64":
                    if (UIDevice.CurrentDevice.Model.Contains("iPhone"))
                        ret = HardwareVersion.iPhoneSimulator;
                    else
                        ret = HardwareVersion.iPadSimulator;
                    break;
                default:
                    ret = HardwareVersion.Unknown;
                    break;
            }
            return ret;
        }
public static HardwareVersion GetHardwareVersion ( ) { var pLen = Marshal . AllocHGlobal ( sizeof ( int ) ) ; sysctlbyname ( HardwareProperty , IntPtr . Zero , pLen , IntPtr . Zero , 0 ) ; var length = Marshal . ReadInt32 ( pLen ) ; var pStr = Marshal . AllocHGlobal ( length ) ; sysctlbyname ( HardwareProperty , pStr , pLen , IntPtr . Zero , 0 ) ; var hardwareStr = Marshal . PtrToStringAnsi ( pStr ) ; var ret = HardwareVersion . Unknown ; switch ( hardwareStr ) { case " " : ret = HardwareVersion . iPhone ; break ; case " " : ret = HardwareVersion . iPhone3G ; break ; case " " : ret = HardwareVersion . iPhone3GS ; break ; case " " : case " " : case " " : ret = HardwareVersion . iPhone4 ; break ; case " " : ret = HardwareVersion . iPhone4S ; break ; case " " : case " " : ret = HardwareVersion . iPhone5 ; break ; case " " : case " " : ret = HardwareVersion . iPhone5C ; break ; case " " : case " " : ret = HardwareVersion . iPhone5S ; break ; case " " : ret = HardwareVersion . iPhone6 ; break ; case " " : ret = HardwareVersion . iPhone6Plus ; break ; case " " : ret = HardwareVersion . iPhone6S ; break ; case " " : ret = HardwareVersion . iPhone6SPlus ; break ; case " " : ret = HardwareVersion . iPhoneSE ; break ; case " " : case " " : ret = HardwareVersion . iPhone7 ; break ; case " " : case " " : ret = HardwareVersion . iPhone7Plus ; break ; case " " : ret = HardwareVersion . iPhone8 ; break ; case " " : ret = HardwareVersion . iPhone8Plus ; break ; case " " : ret = HardwareVersion . iPad ; break ; case " " : case " " : case " " : case " " : ret = HardwareVersion . iPad2 ; break ; case " " : case " " : case " " : ret = HardwareVersion . iPad3 ; break ; case " " : case " " : case " " : ret = HardwareVersion . iPad4 ; break ; case " " : case " " : case " " : ret = HardwareVersion . iPadAir ; break ; case " " : case " " : ret = HardwareVersion . iPadAir2 ; break ; case " " : case " " : ret = HardwareVersion . iPadPro_12_9 ; break ; case " " : case " " : ret = HardwareVersion . iPadPro_9_7 ; break ; case " " : case " " : ret = HardwareVersion . iPadPro_2017 ; break ; case " " : case " " : case " " : ret = HardwareVersion . iPadMini ; break ; case " " : case " " : case " " : ret = HardwareVersion . iPadMini2 ; break ; case " " : case " " : case " " : ret = HardwareVersion . iPadMini3 ; break ; case " " : case " " : ret = HardwareVersion . iPadMini4 ; break ; case " " : ret = HardwareVersion . iPod1G ; break ; case " " : ret = HardwareVersion . iPod2G ; break ; case " " : ret = HardwareVersion . iPod3G ; break ; case " " : ret = HardwareVersion . iPod4G ; break ; case " " : ret = HardwareVersion . iPod5G ; break ; case " " : ret = HardwareVersion . iPod6G ; break ; case " " : case " " : if ( UIDevice . CurrentDevice . Model . Contains ( " " ) ) ret = HardwareVersion . iPhoneSimulator ; else ret = HardwareVersion . iPadSimulator ; break ; default : ret = HardwareVersion . Unknown ; break ; } return ret ; }
Gets the hardware version / model.
Gets the hardware version / model .
The hardware version.
The hardware version .