Delpin Susai Raj Monday 18 September 2017

How to Get Device Info(UDID, Model, Name, OS Version) in Xamarin iOS

In this article, you will learn how to Get Device Info(UDID, Model, Name, OS Version) in Xamarin iOS, using Xamarin Studio.

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.

Download Code Here...




Prerequisites


  1. Xamarin Studio.
  2. Xcode.


The steps given below are required to be followed in order to Get Device Info(UDID, Model, Name, OS Version) in Xamarin iOS, using Xamarin Studio.

Step 1

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



Step 2

In This step Configure your app. Give App name(Ex: sample) and Organization Identifier. and Choose Target Platforms. Next, Choose Shared Code.Afterwards, click Next.



Step 3

In this step Give your Project Name(Ex: Sample). And Solution Name(EX: Sample). and give the path of your project. Afterwards, click Create.



Step 4

Subsequently, Go to Solution. In Solution, get all the files and source in your project. Now, select Main.storyboard double click to open Main.storyboard page.



Step 5

After opening 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.

  Constraints More info refer the following link.

https://developer.xamarin.com/guides/ios/user_interface/designer/designer_auto_layout/



Step 8

Now, go to the Properties Window. Select the First label and give Name(Ex:lblName)



Step 9

Select the Second label and give Name(Ex:lblUDID)



Step 10

Select the Third label and give Name(Ex:lblVersion)




Step 11

Select the Fourth label and give Name(Ex:lblDeviceName)




Step 12

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

ViewController.cs

using System;

using UIKit;

namespace XamariniOSDeviceInfo.iOS
{
 public partial class ViewController : UIViewController
 {
  

  public ViewController(IntPtr handle) : base(handle)
  {
  }

  public override void ViewDidLoad()
  {
   base.ViewDidLoad();

   lblName.Text = UIDevice.CurrentDevice.Name;
   lblVersion.Text = UIDevice.CurrentDevice.SystemVersion;
   lblDeviceName.Text = UIDevice.CurrentDevice.Model;
   lblUDID.Text = UIDevice.CurrentDevice.IdentifierForVendor.ToString();

  }

  public override void DidReceiveMemoryWarning()
  {
   base.DidReceiveMemoryWarning();
   // Release any cached data, images, etc that aren't in use.  
  }
 }
}







Step 13

Now, Go to Run Option Choose Debug. and The List of iPhone, iPad Simulators Available, You can Choose any one and run it.



Output

After few seconds, the app will start running on your iPhone Simulator.You will see your app is work Successfully.



Summary

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

Please share your comments and feedback.


No comments:

Post a Comment