[英]How can I get the current device model on Xamarin Forms?
I wrote a logger class that emails me when there's an exception on my application, but I'd like to know what the model of device is that threw the exception. 我写了一个记录器类,当我的应用程序出现异常时会通过电子邮件发送给我,但是我想知道设备的型号是什么引发了异常。 For example:
例如:
Logger.LogError(App.ApplicationName, Device.OS.ToString(), "Error getting passenger ancillary transactions!", Settings.CurrentUsername, ex.ToString());
Sends an email of the exception with the application's name and the fact that the device is "Android" or "iOS", but nothing more specific than that. 使用应用程序的名称以及设备为“Android”或“iOS”的事实发送异常的电子邮件,但没有更具体的内容。 In Visual Studio, it says which device I'm about to debug on (like "iPod Touch" or "LG LS991").
在Visual Studio中,它说明了我要调试的设备(如“iPod Touch”或“LG LS991”)。 Is there a way to access this information?
有没有办法访问这些信息? I can't find anything in the Xamarin documentation.
我在Xamarin文档中找不到任何内容。
Xamarin.Plugins
by jamesmontemagno work cross-platform within Xamarin.Forms
: Xamarin.Plugins
由jamesmontemagno在Xamarin.Forms
跨平台工作:
You would be looking for the DeviceInfo
plugin: 您将寻找
DeviceInfo
插件:
https://github.com/jamesmontemagno/Xamarin.Plugins/tree/master/DeviceInfo https://github.com/jamesmontemagno/Xamarin.Plugins/tree/master/DeviceInfo
/// <summary>
/// Get the model of the device
/// </summary>
string Model { get; }
/// <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
/// <summary>
/// Get the platform of the device
/// </summary>
Platform { get; }
Returns the Platform Enum of:
public enum Platform
{
Android,
iOS,
WindowsPhone,
Windows
}
Just to complete SushiHangover's answer: On iOS, Model property does not contain full model name(eg you cannot distinguish iPhone 3 and iPhone 4). 只是为了完成SushiHangover的回答:在iOS上,Model属性不包含完整的型号名称(例如,你无法区分iPhone 3和iPhone 4)。
Fortunately, here is some code , that extracts it for you. 幸运的是,这里有一些代码 ,可以为您提取。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.