5.5 C
New York
Friday, March 14, 2025

ios – .NET MAUI – Get machine mannequin quantity


I’m in search of a method to get the machine quantity (particularly for iPhone) in .NET MAUI like this:

iPhone4            => 4,
iPhone4S           => 4,
iPhone5            => 5,
iPhone5S           => 5,
iPhone5C           => 5,
iPhone6            => 6,
iPhone6Plus        => 6,
iPhone6S           => 6,
iPhone6SPlus       => 6,
iPhoneSE           => 6,
iPhone7            => 7,
iPhone7Plus        => 7,
iPhone8            => 8,
iPhone8Plus        => 8,
iPhoneX            => 10,
iPhoneXS           => 10,
iPhoneXSMax        => 10,
iPhoneXR           => 10,
iPhone11           => 11,
iPhone11Pro        => 11,
iPhone11ProMax     => 11,
iPhoneSE2          => 11,
iPhone12Mini       => 12,
iPhone12           => 12,
iPhone12Pro        => 12,
iPhone12ProMax     => 12,
iPhone13Mini       => 13,
iPhone13           => 13,
iPhone13Pro        => 13,
iPhone13ProMax     => 13,
iPhoneSE3          => 13,
iPhone14           => 14,
iPhone14Plus       => 14,
iPhone14Pro        => 14,
iPhone14ProMax     => 14,
iPhone15           => 15,
iPhone15Plus       => 15,
iPhone15Pro        => 15,
iPhone15ProMax     => 15,
iPhone16           => 16,
iPhone16Plus       => 16,
iPhone16Pro        => 16,
iPhone16ProMax     => 16,
iPhone16e          => 16,

I do know there have to be a method to get the identifiers like iPhone11,2 (iPhone XS) or iPhone17,3 (iPhone 16) like on this publish: The way to decide the present iPhone/machine mannequin?

However I cant determine how one can get them.

All I acquired is to make use of Microsoft.Maui.Gadgets.DeviceInfo

Utilizing DeviceInfo.Mannequin solely returns “iPhone” with none information concerning the mannequin quantity.

I wrote a prototype technique that reads the quantity by way of regex from the string returned by DeviceInfo.Title which returns one thing like “iPhone 16” by way of regex

public static bool IsIphoneModelNoHigherThan(int modelNo) 
{
    string deviceName = DeviceInfo.Present.Title;

    Match match = Regex.Match(deviceName, @"iPhones*(d+)");

    if (match.Success && int.TryParse(match.Teams[1].Worth, out int modelNumber))
    {
        return modelNumber > modelNo;
    }
    
    return false;
}

This in fact doesn’t work with fashions like iPhone SE/X/XR so I’m in search of a safer method to do it however DeviceInfo doesn’t appears to ship a lot details about the mannequin quantity.

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles