代码之家  ›  专栏  ›  技术社区  ›  Om Singh

如何检测iOS设备类型Xamarin

  •  0
  • Om Singh  · 技术社区  · 2 年前

    我想首先检测什么是平台,我想检测的是它是手机还是平板电脑。 我在互联网上搜索了很多可以用屏幕大小(如高度和宽度)来检测的例子,但是有什么可以让你知道设备的类型。

    if(Device.RuntimePlatform == Device.iOS)
    {
        //what is the device type 
    }
    else if(Device.RuntimePlatform == Device.Android)
    {
        //what is the device type
    }
    
    1 回复  |  直到 2 年前
        1
  •  1
  •   TheHunter Shergill Stan R.    2 年前

    使用此选项可检测设备类型。

    
    if(Device.RuntimePlatform == Device.iOS)
    {
        //what is the device type
       if (Device.Idiom == TargetIdiom.Phone)
       {
           Console.WriteLine(Device.Idiom);
       }
       else if(Device.Idiom == TargetIdiom.Tablet)
       {
           Console.WriteLine(Device.Idiom);
       } 
    
    }
    else if(Device.RuntimePlatform == Device.Android)
    {
        //what is the device type
    }