6

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.

2 Answers 2

11

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

Nuget search: 'Device Info Plugin for Xamarin and Windows'

Device Model

/// <summary>
/// Get the model of the device
/// </summary>
string Model { get; }

Version

/// <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

Platform

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

Platform { get; }

Returns the Platform Enum of:

public enum Platform
{
  Android,
  iOS,
  WindowsPhone,
  Windows
}
Sign up to request clarification or add additional context in comments.

1 Comment

Just wanted to add that CrossDeviceInfo.Current.Model is what gets the actual model string.
5

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.

1 Comment

How would I use this from xamarin forms ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.