gpt4 book ai didi

c# - 如何在 Xamarin Forms 上获取当前设备型号?

转载 作者:太空狗 更新时间:2023-10-29 20:56:15 26 4
gpt4 key购买 nike

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

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 文档中找不到任何内容。

最佳答案

Xamarin.Plugins by 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
}

关于c# - 如何在 Xamarin Forms 上获取当前设备型号?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36699251/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com