xamarin / Essentials

Xamarin.Essentials is no longer supported. Migrate your apps to .NET MAUI, which includes Maui.Essentials.
https://aka.ms/xamarin-upgrade
Other
1.53k stars 506 forks source link

Unable to detect Apps on M1 and M2 Macs #2089

Open logikonline opened 1 year ago

logikonline commented 1 year ago

Description

Essentials doesn't properly detect apps on the MacOS, mistaking them for Tablets

Steps to Reproduce

  1. Install on M1 or M2
  2. Read device Idiom

Expected Behavior

Should report Desktop

Actual Behavior

Reports Tablet

logikonline commented 1 year ago
        switch (UIDevice.CurrentDevice.UserInterfaceIdiom)
        {
            case UIUserInterfaceIdiom.Pad:
                return DeviceIdiom.Tablet;
            case UIUserInterfaceIdiom.Phone:
                return DeviceIdiom.Phone;
            case UIUserInterfaceIdiom.TV:
                return DeviceIdiom.TV;
            case UIUserInterfaceIdiom.CarPlay:
            case UIUserInterfaceIdiom.Unspecified:
            default:
                return DeviceIdiom.Unknown;
        }

Add
case UIUserInterfaceIdiom.Mac: return DeviceIdiom.Desktop;

To this code section https://github.com/xamarin/Essentials/blob/25ceeea887c50e5194d746bd159be1f143e26157/Xamarin.Essentials/DeviceInfo/DeviceInfo.ios.tvos.watchos.cs#L51

logikonline commented 1 year ago

Please fix this in Maui too

logikonline commented 1 year ago

If additional helper routines are needed, these should assist the dev.

`//A Boolean value that indicates whether the process is an iPhone or iPad app running on a Mac.