Спасибо, Joachim, ваша подсказка привела меня к следующему решению, которое я протестировал на физических iPad 1-3 поколения, и оно также должно быть в состоянии обнаружить другие устройства Apple:
public enum HardwareVersion
{
iPhone2G,
iPhone3G,
iPhone3Gs,
iPhone4,
iPod1G,
iPod2G,
iPod3G,
Simulator,
iPad1G,
iPad2G,
iPad3G,
Unknown
}
[DllImport(MonoTouch.Constants.SystemLibrary)]
static internal extern int sysctlbyname ([MarshalAs(UnmanagedType.LPStr)] string property, IntPtr output, IntPtr oldLen, IntPtr newp, uint newlen);
public static HardwareVersion getHardwareVersion()
{
string HardwareProperty = "hw.machine";
// get the length of the string that will be returned
var pLen = Marshal.AllocHGlobal (sizeof(int));
sysctlbyname (HardwareProperty, IntPtr.Zero, pLen, IntPtr.Zero, 0);
var length = Marshal.ReadInt32 (pLen);
// check to see if we got a length
if (length == 0) {
Marshal.FreeHGlobal (pLen);
return HardwareVersion.Unknown;
}
// get the hardware string
var pStr = Marshal.AllocHGlobal (length);
sysctlbyname (HardwareProperty, pStr, pLen, IntPtr.Zero, 0);
// convert the native string into a C# string
var hardwareStr = Marshal.PtrToStringAnsi (pStr);
var ret = HardwareVersion.Unknown;
// determine which hardware we are running
if (hardwareStr == "iPhone1,1")
ret = HardwareVersion.iPhone2G;
else if (hardwareStr == "iPhone1,2")
ret = HardwareVersion.iPhone3G;
else if (hardwareStr == "iPhone2,1")
ret = HardwareVersion.iPhone3Gs;
else if (hardwareStr == "iPhone3,1")
ret = HardwareVersion.iPhone4;
else if (hardwareStr == "iPod1,1")
ret = HardwareVersion.iPod1G;
else if (hardwareStr == "iPod2,1")
ret = HardwareVersion.iPod2G;
else if (hardwareStr == "iPod3,1")
ret = HardwareVersion.iPod3G;
else if (hardwareStr == "iPad1,1")
ret = HardwareVersion.iPad1G;
else if (hardwareStr == "iPad2,1")
ret = HardwareVersion.iPad2G;
else if (hardwareStr == "iPad3,1")
ret = HardwareVersion.iPad3G;
else if (hardwareStr == "i386" || hardwareStr == "x86_64" || hardwareStr == "x86_32" )
ret = HardwareVersion.Simulator;
// cleanup
Marshal.FreeHGlobal (pLen);
Marshal.FreeHGlobal (pStr);
return ret;
}