How To Get Device Info (UDID, Model, Name, OS Version) In Xamarin iOS App

Introduction

Xamarin is a platform to develop cross-platform and multi-platform apps (for example, Windows phone, Android, iOS). In Xamarin platform, the code sharing concept is used. In Xamarin Studio, Visual Studio is also available.

Prerequisites
  • Xamarin Studio.
  • Xcode.
The steps given below are required to be followed in order to get the device information (UDID, Model, Name, OS Version) in Xamarin iOS, using Xamarin Studio.

Step 1

Go To Xamarin Studio.

Click New Solution—> select Multiplatform—>select App--> Choose single View App. Native (iOS,Android). Afterwards, click Next.



Step 2

In this step, configure your app. Give the app name (Ex:sample), Organization Identifier and Choose Target Platforms. Now, choose shared code. Afterwards, click Next.

 

step 3

In this step, give your project name (Ex: Sample) and solution name (Ex: Sample). Give the path of your project. Afterwards, click Create.

 

Step 4

Subsequently, go to the solution. In the solution, get all the files and sources in your project. Now, select Main.storyboard and double click to open Main.storyboard page.

 

Step 5

After opening the Main.storyboard, you can design this page, as per your desire.

 

Step 6

Now, go to the toolbox Window. In the toolbox Window, get all the types of the tools and controls. You need to go to the toolbox Window. Now, scroll down and you will see all the tools and controls. You need to drag and drop the label.

 

Step 7

You need to drag and drop four labels and align the labels, using constraints, which can be learned here.



Step 8

Now, go to the properties Window. Select the first label and give a name (Ex:lblName).

 

Step 9

Select the second label and give a name (Ex:lblUDID).

 

Step 10

Select the third label and give a name (Ex:lblVersion).

 

Step 11

Select the fourth label and give a name (Ex:lblDeviceName).

 

Step 12

In this step, go to the ViewController.cs page. Write the code given below.

ViewController.cs
  1. using System;  
  2. using UIKit;  
  3. namespace XamariniOSDeviceInfo.iOS {  
  4.     public partial class ViewController: UIViewController {  
  5.         public ViewController(IntPtr handle): base(handle) {}  
  6.         public override void ViewDidLoad() {  
  7.             base.ViewDidLoad();  
  8.             lblName.Text = UIDevice.CurrentDevice.Name;  
  9.             lblVersion.Text = UIDevice.CurrentDevice.SystemVersion;  
  10.             lblDeviceName.Text = UIDevice.CurrentDevice.Model;  
  11.             lblUDID.Text = UIDevice.CurrentDevice.IdentifierForVendor.ToString();  
  12.         }  
  13.         public override void DidReceiveMemoryWarning() {  
  14.             base.DidReceiveMemoryWarning();  
  15.             // Release any cached data, images, etc that aren't in use.  
  16.         }  
  17.     }  
  18. }  

Step 13

Now, go to Run option , choose Debug and the list of iPhone and iPad simulators, which are available. You can choose any one simulator and run it.

 

Output

After a few seconds, the app will start running on your iPhone simulator.You will see your app working successfully.



Summary

This was the process of how to get device infomation (UDID, Model, Name, OS Version) in Xamarin iOS, using Xamarin Studio.

Up Next
    Ebook Download
    View all
    Learn
    View all