2016-04-18 45 views
3

我写了一个记录器类,当我的应用程序出现异常时通过电子邮件发送给我,但我想知道抛出异常的设备型号是什么。例如:如何获取Xamarin Forms上的当前设备模型?

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

发送带有应用程序的名称异常和该设备的“Android”或“iOS版”的事实,但没有什么比这更具体的电子邮件。在Visual Studio中,它说明了我要调试的设备(如“iPod Touch”或“LG LS991”)。有没有办法访问这些信息?我在Xamarin文档中找不到任何东西。

回答

6

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; } 

版本

/// <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 
} 
+0

只是想补充一点''CrossDeviceInfo.Current.Model'是什么得到实际的模型字符串。 – aufty

2

只是为了完成SushiHangover的回答是: 在iOS上,Model属性不包含完整的型号名称(例如。你不能区分iPhone 3和iPhone 4)。

幸运的是,这里是some code,它为你提取它。

相关问题