如何在Xamarin Forms上获取当前的设备模型?

auf*_*fty 6 c# xamarin xamarin.forms

我写了一个记录器类,当我的应用程序出现异常时,它会给我发电子邮件,但我想知道设备的型号是什么引发了异常.例如:

Logger.LogError(App.ApplicationName, Device.OS.ToString(), "Error getting passenger ancillary transactions!", Settings.CurrentUsername, ex.ToString());
Run Code Online (Sandbox Code Playgroud)

使用应用程序的名称以及设备为"Android"或"iOS"的事实发送异常的电子邮件,但没有更具体的内容.在Visual Studio中,它说明了我要调试的设备(如"iPod Touch"或"LG LS991").有没有办法访问这些信息?我在Xamarin文档中找不到任何内容.

Sus*_*ver 11

Xamarin.Plugins作者:jamesmontemagno跨平台工作Xamarin.Forms:

你会寻找DeviceInfo插件:

https://github.com/jamesmontemagno/Xamarin.Plugins/tree/master/DeviceInfo

Nuget搜索:"Xamarin和Windows的设备信息插件"

设备模型

/// <summary>
/// Get the model of the device
/// </summary>
string Model { get; }
Run Code Online (Sandbox Code Playgroud)

/// <summary>
/// Get the version of the Operating System
/// </summary>
string Version { get; }
Returns the specific version number of the OS such as:

iOS: 8.1
Android: 4.4.4
Windows Phone: 8.10.14219.0
WinRT: always 8.1 until there is a work around
Run Code Online (Sandbox Code Playgroud)

平台

/// <summary>
/// Get the platform of the device
/// </summary>

Platform { get; }

Returns the Platform Enum of:

public enum Platform
{
  Android,
  iOS,
  WindowsPhone,
  Windows
}
Run Code Online (Sandbox Code Playgroud)


Fla*_*239 5

只是为了完成SushiHangover的答案:在iOS上,“模型”属性不包含完整的模型名称(例如,您无法区分iPhone 3和iPhone 4)。

幸运的是,这里有一些代码,可以为您提取代码