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. In Visual Studio, it says which device I'm about to debug on (like "iPod Touch" or "LG LS991"). Is there a way to access this information? I can't find anything in the Xamarin documentation.
For version check Help/About and then click Show Details. For Visual Studio updates go to Tools/Options and then Xamarin from the left tree. Below you'll find Xamarin.
Xamarin support will end on May 1, 2024 for all Xamarin SDKs. Android 13 and Xcode 14 SDKs (iOS and iPadOS 16, macOS 13) will be the final versions Xamarin will target.
You can find the version of your Xamarin plug-ins for Visual Studio by going to "Help" -> "About Microsoft Visual Studio" in VS, and scrolling down to the Xamarin plug-ins.
Xamarin.Plugins
by jamesmontemagno work cross-platform within Xamarin.Forms
:
You would be looking for the DeviceInfo
plugin:
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(e.g. you cannot distinguish iPhone 3 and iPhone 4).
Fortunately, here is some code, that extracts it for you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With