Use case: Obtain low level iOS device model number in "developer" format (unmapped to actual device model) using the "hw.machine" system level property. Would be great if we could expose this property. Leave the mapping to the user so it doesn't need to be maintained here for every iOS device release.
public string MobileDeviceModelSpecific
{
get
{
var hardwareVersion = GetSystemProperty("hw.machine");
var regex = new Regex("iPhone([0-9]+),([0-9]+)").Match(hardwareVersion);
if (regex.Success)
{
return UIDevice.CurrentDevice.Model + int.Parse(regex.Groups[1].Value) + '.' + int.Parse(regex.Groups[2].Value);
}
regex = new Regex("iPod([0-9]+),([0-9]+)").Match(hardwareVersion);
if (regex.Success)
{
return UIDevice.CurrentDevice.Model + int.Parse(regex.Groups[1].Value) + '.' + int.Parse(regex.Groups[2].Value);
}
regex = new Regex("iPad([0-9]+),([0-9]+)").Match(hardwareVersion);
if (regex.Success)
{
return UIDevice.CurrentDevice.Model + int.Parse(regex.Groups[1].Value) + '.' + int.Parse(regex.Groups[2].Value);
}
return UIDevice.CurrentDevice.Model + "0.0";
}
}
[DllImport(ObjCRuntime.Constants.SystemLibrary)]
internal static extern int sysctlbyname(
[MarshalAs(UnmanagedType.LPStr)] string property,
IntPtr output,
IntPtr oldLen,
IntPtr newp,
uint newlen);
[DllImport(ObjCRuntime.Constants.SystemLibrary)]
static internal extern int sysctl(
[MarshalAs(UnmanagedType.LPArray)] int[] name,
uint namelen,
out uint oldp,
ref int oldlenp,
IntPtr newp,
uint newlen);
public static string GetSystemProperty(string property)
{
var pLen = Marshal.AllocHGlobal(sizeof(int));
sysctlbyname(property, IntPtr.Zero, pLen, IntPtr.Zero, 0);
var length = Marshal.ReadInt32(pLen);
var pStr = Marshal.AllocHGlobal(length);
sysctlbyname(property, pStr, pLen, IntPtr.Zero, 0);
return Marshal.PtrToStringAnsi(pStr);
}
Example Output:
iPhone9,2 (iPhone 7+)
Mappings can be found here: https://www.theiphonewiki.com/wiki/Models (Generation, Identifier columns)
While I do think this is an API that some developers can use, I think that it is too brittle and needs constant updating. Additionally, I would fear scanning on Apple's end when submitting apps. So for that I don't think we can proceed om something like this.
Just in case anyone stumbles up on this... I use Get-iOS-Model in most of my projects and it works great.
@jamesmontemagno I'd say this is a really essential feature, iPhone9,3 means nothing to most people whereas iPhone 7 is more useful information. I can understand the maintainability aspect to a degree, but this is apple we are talking about. The list will have to be updated once a year in September, it would make the essentials library more essential. @aherrick is adding a nuget package that now adds a double dependancy, I use a gist (this beast) to do the same thing.
For items like this we are delivering the raw information back which is delivered by iOS or Android. The moment any new phone comes out then the library is forced to update (which is about every day for android) and causes a maintenance nightmare. Developers using this API most likely are using it for tracking types of devices for analytics and their backends should parse this data. Adding tons of data that is not official or maintained and may change randomly isn't in the spirit of the library.
Most helpful comment
For items like this we are delivering the raw information back which is delivered by iOS or Android. The moment any new phone comes out then the library is forced to update (which is about every day for android) and causes a maintenance nightmare. Developers using this API most likely are using it for tracking types of devices for analytics and their backends should parse this data. Adding tons of data that is not official or maintained and may change randomly isn't in the spirit of the library.