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
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
- 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();
-
- }
- }
- }
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.