Delpin Susai Raj Saturday 28 July 2018

Xamarin.Forms - Trun ON/Off Flashlight Using Xamarin Essentials

In this blog,  you will learn how to turn on or off flashlight. Using Xamarin.Essentials in Xamarin forms. 


Introduction
  1. Xamarin.Forms - AppInfo Using Xamarin Essentials
  2. Xamarin.Forms - DeviceInfo Using Xamarin Essentials
  3. Xamarin.Forms - Check Internet Connection Using Xamarin Essentials
  4. Xamarin.Forms - Clipboard (Copy And Paste Text) Using Xamarin Essentials



Xamarin.Forms code runs on multiple platforms - each of which has its own filesystem. This means that reading and writing files is most easily done using the native file APIs on each platform. Alternatively, embedded resources are a simpler solution to distribute data files with an app.

Xamarin.Essentials



Xamarin.Essentials plugin provides 20+ cross-platform APIs for  mobile application development. Xamarin.Essentials API works with all Xamarin.Forms, Xamarin.Android, Xamarin.iOS, or UWP application that can be accessed from shared code. When we are developing Xamarin with Android, iOS and UWP apps but now Xamarin.Essentials overcome the problem, developers can access every native platform API using C#. This plugin provides many APIs so initially, there is no need of more plugins for Xamarin. Xamarin.Essentials plugin impacts your app's minimum size.



Platform Support

Xamarin.Essentials supports platforms and operating systems

Platform Version
Android 4.4 (API 19) or earlier
iOS 10.0 or higher
UWP 10.0.16299.0 or earlier

Prerequisites
  • Visual Studio 2017(Windows or Mac)

Setting up a Xamarin.Forms Project


Start by creating a new Xamarin.Forms project.  you’ll learn more by going through the steps yourself.
Choose the Xamarin.Forms App Project type under Cross-platform/App in the New Project dialog.



Name your app, select “Use Portable Class Library” for shared code, and target both Android and iOS.



You probably want your project and solution to use the same name as your app. Put it in your preferred folder for projects and click Create.



You now have a basic Xamarin.Forms app. Click the play button to try it out.



Setting up the User Interface

Go to MainPage.Xaml and write the following code.

MainPage.xaml

Add Xamarin Essentials

In this step, add Xamarin.Essentials to your project. You can install Xamarin.Essentials via NuGet, or you can browse the source code on GitHub.

Go to Solution Explorer and select your solution. Right-click and select "Manage NuGet Packages for Solution". Search "Xamarin.Essentials" and add Package. Remember to install it for each project (PCL, Android, iO, and UWP).



Xamarin.Essentials requires platform-specific setup

Android

The following steps are necessary for Android.
  1. Xamarin.Essentials supports a minimum Android version of 4.4
  2. Target Android version for compiling must be 8.1, API level 27.
In the Android project's MainActivity that is launched Xamarin.Essentials must be initialized in the OnCreate method.

MainActivity.cs

Xamarin.Essentials must receive any OnRequestPermissionsResult. write the following code for runtime permission.

MainActivity.cs

iOS

No additional setup required.

UWP

No additional setup required.


Permissions

In this step give the following required permissions to your app:
  1. CAMERA
  2. FLASHLIGHT
Limitation
  • It supports Device only not Simulator/Emulator
In this step, write the following code for ON Flashlight.

MainPage.xaml.cs


async void Handle_Clicked(object sender, System.EventArgs e)
        {
            try
            {
                // Turn On Flashlight
                await Flashlight.TurnOnAsync();
            }
            catch (FeatureNotSupportedException fnsEx)
            {
                await ShowAlert(fnsEx.Message);
            }
            catch (PermissionException pEx)
            {
                await ShowAlert(pEx.Message);
            }
            catch (Exception ex)
            {
                await ShowAlert(ex.Message);
            }
        }




Now, write the following code for Off Flashlight.

MainPage.xaml.cs


async void Handle_Clicked_1(object sender, System.EventArgs e)
        {
            try
            {
                // Turn Off Flashlight
                await Flashlight.TurnOffAsync();
            }
            catch (FeatureNotSupportedException fnsEx)
            {
                await ShowAlert(fnsEx.Message);
            }
            catch (PermissionException pEx)
            {
                await ShowAlert(pEx.Message);
            }
            catch (Exception ex)
            {
                await ShowAlert(ex.Message);
            }
        }


Full code - MainPage.xaml.cs

using Xamarin.Forms;
using Xamarin.Essentials;
namespace XamarinEssentials
{
    public partial class MainPage : ContentPage
    {
        public MainPage()
        {
            InitializeComponent();
        }

        async void Handle_Clicked(object sender, System.EventArgs e)
        {
            try
            {
                // Turn On Flashlight
                await Flashlight.TurnOnAsync();
            }
            catch (FeatureNotSupportedException fnsEx)
            {
                await ShowAlert(fnsEx.Message);
            }
            catch (PermissionException pEx)
            {
                await ShowAlert(pEx.Message);
            }
            catch (Exception ex)
            {
                await ShowAlert(ex.Message);
            }
        }

        async void Handle_Clicked_1(object sender, System.EventArgs e)
        {
            try
            {
                // Turn Off Flashlight
                await Flashlight.TurnOffAsync();
            }
            catch (FeatureNotSupportedException fnsEx)
            {
                await ShowAlert(fnsEx.Message);
            }
            catch (PermissionException pEx)
            {
                await ShowAlert(pEx.Message);
            }
            catch (Exception ex)
            {
                await ShowAlert(ex.Message);
            }
        }

        public async Task ShowAlert(string message)
        {
            await DisplayAlert("Faild", message, "Ok");
        }
    }
}


Click the play button to try it out.



Related post

  1. Xamarin.Forms - AppInfo Using Xamarin Essentials
  2. Xamarin.Forms - DeviceInfo Using Xamarin Essentials
  3. Xamarin.Forms - Check Internet Connection Using Xamarin Essentials
  4. Xamarin.Forms - Clipboard (Copy And Paste Text) Using Xamarin Essentials

I hope you have understood how to turn on or off flashlight Using Xamarin Essentials in Xamarin.Forms.
Thanks for reading. Please share comments and feedback.
Delpin Susai Raj Thursday 26 July 2018

Xamarin.Forms - Clipboard(Copy and Paste text) Using Xamarin Essentials

In this blog,  you will learn how to Copy and Paste text Using Xamarin.Essentials in Xamarin forms. 


Introduction
  1. Xamarin.Forms - AppInfo Using Xamarin Essentials
  2. Xamarin.Forms - DeviceInfo Using Xamarin Essentials
  3. Xamarin.Forms - Check Internet Connection Using Xamarin Essentials



Xamarin.Forms code runs on multiple platforms - each of which has its own filesystem. This means that reading and writing files is most easily done using the native file APIs on each platform. Alternatively, embedded resources are a simpler solution to distribute data files with an app.

Xamarin.Essentials



Xamarin.Essentials plugin provides 20+ cross-platform APIs for  mobile application development. Xamarin.Essentials API works with all Xamarin.Forms, Xamarin.Android, Xamarin.iOS, or UWP application that can be accessed from shared code. When we are developing Xamarin with Android, iOS and UWP apps but now Xamarin.Essentials overcome the problem, developers can access every native platform API using C#. This plugin provides many APIs so initially, there is no need of more plugins for Xamarin. Xamarin.Essentials plugin impacts your app's minimum size.

Platform Support

Xamarin.Essentials supports platforms and operating systems

Platform Version
Android 4.4 (API 19) or earlier
iOS             10.0 or higher
UWP 10.0.16299.0 or earlier

Prerequisites
  • Visual Studio 2017(Windows or Mac)
Setting up a Xamarin.Forms Project

Start by creating a new Xamarin.Forms project.  you’ll learn more by going through the steps yourself.
Choose the Xamarin.Forms App Project type under Cross-platform/App in the New Project dialog.



Name your app, select “Use Portable Class Library” for shared code, and target both Android and iOS.



You probably want your project and solution to use the same name as your app. Put it in your preferred folder for projects and click Create.



You now have a basic Xamarin.Forms app. Click the play button to try it out.



Setting up the User Interface

Go to MainPage.Xaml and write the following code.

MainPage.xaml

Add Xamarin Essentials

In this step, add Xamarin.Essentials to your project. You can install Xamarin.Essentials via NuGet, or you can browse the source code on GitHub.

Go to Solution Explorer and select your solution. Right-click and select "Manage NuGet Packages for Solution". Search "Xamarin.Essentials" and add Package. Remember to install it for each project (PCL, Android, iO, and UWP).



Xamarin.Essentials requires platform-specific setup

Android

The following steps are necessary for Android.

  1. Xamarin.Essentials supports a minimum Android version of 4.4
  2. Target Android version for compiling must be 8.1, API level 27.

In the Android project's MainActivity that is launched Xamarin.Essentials must be initialized in the OnCreate method.

MainActivity.cs

Xamarin.Essentials must receive any OnRequestPermissionsResult. write the following code for runtime permission.

MainActivity.cs

iOS

No additional setup required.

UWP

No additional setup required.

In this step, write the following code for Copy and paste text using Clipboard.


MainPage.xaml.cs

using Xamarin.Forms;
using Xamarin.Essentials;
namespace XamarinEssentials
{
 public partial class MainPage : ContentPage
 {
  public MainPage()
  {
   InitializeComponent();

            var tapGestureRecognizer = new TapGestureRecognizer();
            tapGestureRecognizer.Tapped += async (s, e) => {
                Clipboard.SetText(lblCopy.Text);
                if (Clipboard.HasText)
                {
                    var text = await Clipboard.GetTextAsync();
                    DisplayAlert("Success",string.Format("Your copied text is({0})",text),"OK");
                }
            };
            lblCopy.GestureRecognizers.Add(tapGestureRecognizer);

  }
 }
}


Click the play button to try it out.





Related post


  1. Xamarin.Forms - AppInfo Using Xamarin Essentials
  2. Xamarin.Forms - DeviceInfo Using Xamarin Essentials
  3. Xamarin.Forms - Check Internet Connection Using Xamarin Essentials


I hope you have understood how to Copy and Paste text Using Xamarin Essentials in Xamarin.Forms.
Thanks for reading. Please share comments and feedback.
Delpin Susai Raj Tuesday 24 July 2018

Xamarin.Forms- Check Internet Connection Using Xamarin Essentials

In this blog you will learn how to Check Internet Connectivity Using Xamarin.Essentials in Xamarin forms. 


Introduction

Related Posts

  1. Xamarin.Forms - AppInfo Using Xamarin Essentials
  2. Xamarin.Forms - DeviceInfo Using Xamarin Essentials





Xamarin.Forms code runs on multiple platforms - each of which has its own filesystem. This means that reading and writing files is most easily done using the native file APIs on each platform. Alternatively, embedded resources are a simpler solution to distribute data files with an app.

Xamarin.Essentials 




Xamarin.Essentials plugin provides 20+ cross-platform APIs for  mobile application development. Xamarin.Essentials API works with all Xamarin.Forms, Xamarin.Android, Xamarin.iOS, or UWP application that can be accessed from shared code. When we are developing Xamarin with Android, iOS and UWP apps but now Xamarin.Essentials overcome the problem, developers can access every native platform API using C#. This plugin provides many APIs so initially, there is no need of more plugins for Xamarin. Xamarin.Essentials plugin impacts your app's minimum size.


Platform Support

Xamarin.Essentials supports platforms and operating systems

Platform    Version

Android    4.4 (API 19) or earlier
iOS           10.0 or higher
UWP        10.0.16299.0 or earlier

Prerequisites
  • Visual Studio 2017(Windows or Mac)

Setting up a Xamarin.Forms Project

Start by creating a new Xamarin.Forms project.  you’ll learn more by going through the steps yourself.

Choose the Xamarin.Forms App Project type under Cross-platform/App in the New Project dialog.



Name your app, select “Use Portable Class Library” for shared code, and target both Android and iOS.



You probably want your project and solution to use the same name as your app. Put it in your preferred folder for projects and click Create.



You now have a basic Xamarin.Forms app. Click the play button to try it out.



Setting up the User Interface

Go to MainPage.Xaml and write the following code.

MainPage.xaml

Add Xamarin Essentials

In this step, add Xamarin.Essentials to your project. You can install Xamarin.Essentials via NuGet, or you can browse the source code on GitHub.

Go to Solution Explorer and select your solution. Right-click and select "Manage NuGet Packages for Solution". Search "Xamarin.Essentials" and add Package. Remember to install it for each project (PCL, Android, iO, and UWP).



Xamarin.Essentials requires platform-specific setup

Android

The following steps are necessary for Android.
  1. Xamarin.Essentials supports a minimum Android version of 4.4
  2. Target Android version for compiling must be 8.1, API level 27.
In the Android project's MainActivity that is launched Xamarin.Essentials must be initialized in the OnCreate method.

MainActivity.cs

Xamarin.Essentials must receive any OnRequestPermissionsResult. write the following code for runtime permission.

MainActivity.cs

iOS

No additional setup required.

UWP

No additional setup required.

In this step, write the following code for get App Information.

Connectivity.NetworkAccess
  1. Internet-Local and internet access
  2. Local – Local network access only(not internet access)
  3. ConstrainedInternet – Limited internet access
  4. None –Connectivity is not available.
  5. Unknown – Unable to determine internet connectivity.

MainPage.xaml.cs

using Xamarin.Forms;
using Xamarin.Essentials;
namespace XamarinEssentials
{
 public partial class MainPage : ContentPage
 {
  public MainPage()
  {
   InitializeComponent();
            var current = Connectivity.NetworkAccess;
            var profiles = Connectivity.Profiles;
            if (current == NetworkAccess.Internet)
            {
                lblNetworkStatus.Text = "Network is Available";
            }
            else
            {
                lblNetworkStatus.Text = "Network is Not Available";
            }

            if (profiles.Contains(ConnectionProfile.WiFi))
            {
                lblNetworkProfile.Text = profiles.FirstOrDefault().ToString();
            }
            else
            {
                lblNetworkProfile.Text = profiles.FirstOrDefault().ToString();
            }

  }
 }
}



Click the play button to try it out.




Related Post

Xamarin.Forms - AppInfo Using Xamarin Essentials

Xamarin.Forms - DeviceInfo Using Xamarin Essentials


I hope you have understood how to Check Internet Connectivity Using Xamarin Essentials in Xamarin.Forms.
Thanks for reading. Please share comments and feedback.
Delpin Susai Raj Thursday 12 July 2018

Xamarin.Forms - AppInfo Using Xamarin Essentials

In this blog, you will learn how to get App Info Using Xamarin.Essentials in Xamarin forms.

Introduction



Xamarin.Forms code runs on multiple platforms - each of which has its own filesystem. This means that reading and writing files is most easily done using the native file APIs on each platform. Alternatively, embedded resources are a simpler solution to distribute data files with an app.

Xamarin.Essentials 



Xamarin.Essentials plugin provides 20+ cross-platform APIs for the mobile applications development. Xamarin.Essentials API works with all Xamarin.Forms, Xamarin.Android, Xamarin.iOS, or UWP application that can be accessed from shared code. When we developing Xamarin with Android ,iOS and UWP apps but now Xamarin.Essentials overcome the problem, developers can access every native platform APIs using C#. this plugin provide many apis so no need more plugin for xamarin. Xamarin.Essentials plugin impact on your app minimal size.

Platform Support

Xamarin.Essentials supports platforms and operating systems:

Platform Version


  • Android    4.4 (API 19) or earlier
  • iOS           10.0 or higher
  • UWP   10.0.16299.0 or earlier


Prerequisites
  • Visual Studio 2017(Windows or Mac)
Setting up a Xamarin.Forms Project

Start by creating a new Xamarin.Forms project.  you’ll learn more by going through the steps yourself.
Choose the Xamarin.Forms App Project type under Cross-platform/App in the New Project dialog.


Name your app, select “Use Portable Class Library” for shared code, and target both Android and iOS.



You probably want your project and solution to use the same name as your app. Put it in your preferred folder for projects and click Create.


You now have a basic Xamarin.Forms app. Click the play button to try it out.



Setting up the User Interface

Go to MainPage.Xaml and write the following code.

MainPage.xaml

Add Xamarin Essentials

In this step, add Xamarin.Essentials to your project. You can install Xamarin.Essentials via NuGet, or you can browse the source code on GitHub.

Go to Solution Explorer and select your solution. Right-click and select "Manage NuGet Packages for Solution". Search "Xamarin.Essentials" and add Package. Remember to install it for each project (PCL, Android, iO, and UWP).

Xamarin.Essentials requires platform-specific setup

Android

The following steps must for android.
  1. Xamarin.Essentials supports a minimum Android version of 4.4
  2. Target Android version for compiling must be 8.1, API level 27.
In the Android project's MainActivity that is launched Xamarin.Essentials must be initialized in the OnCreate method.

Xamarin.Essentials must receive any OnRequestPermissionsResult. write the following code for runtime permission.
iOS

No additional setup required.

UWP

No additional setup required.

In this step, write the following code for get App Information.


MainPage.xaml.cs

using Xamarin.Forms;
using Xamarin.Essentials;
namespace XamarinEssentials
{
 public partial class MainPage : ContentPage
 {
  public MainPage()
  {
   InitializeComponent();
             
            lblAppName.Text ="App Name :"+ AppInfo.Name;
            lblPackageName.Text ="Package Name :"+ AppInfo.PackageName;
            lblVersion.Text ="Version :"+ AppInfo.VersionString;
            lblBuildNumber.Text ="Build Number :" + AppInfo.BuildString;
           
  }
 }
}


Click the play button to try it out.



I hope you have understood how to get App Info Using Xamarin Essentials in Xamarin.Forms.
Thanks for reading. Please share comments and feedback.
Delpin Susai Raj Thursday 5 July 2018

Xamarin.Forms- DeviceInfo Using Xamarin Essentials

In this blog you will learn how to get DeviceInfo Using Xamarin Essentials in Xamarin forms. 


Introduction



Xamarin.Forms code runs on multiple platforms - each of which has its own filesystem. This means that reading and writing files is most easily done using the native file APIs on each platform. Alternatively, embedded resources are a simpler solution to distribute data files with an app.

Xamarin.Essentials 

Xamarin.Essentials provides developers with cross-platform APIs for their mobile applications.
Android, iOS, and UWP offer unique operating system and platform APIs that developers have access to all in C# leveraging Xamarin. Xamarin.Essentials provides a single cross-platform API that works with any Xamarin.Forms, Android, iOS, or UWP application that can be accessed from shared code no matter how the user interface is created.



When developing iOS and Android apps with Xamarin, developers can access every native platform API using C#. These bindings not only expose the platform APIs in C#, but add powerful C# features, such as async/await, events, delegates, and more. This is a huge advantage for developers, because they never have to leave C#, whether they’re writing shared business logic, user interface, or accessing native features. One key feature developers often look for when developing cross-platform apps with Xamarin is a way to access common native features from their shared code without having to write their own abstractions or find an open source plugin created by the community.


Xamarin.Essentials APIs

Xamarin.Essentials APIs provide access to over 25 native features from a single cross-platform API library, which can be accessed from shared code no matter how the user interface is created. This means you can use Xamarin.Essentials APIs with a single Xamarin.Android app or a Xamarin.Forms app targeting iOS, Android, and UWP. Even though it’s packed with features, it’s still fully optimized for performance and minimal impact on app size, because the library takes full advantage of being linker safe. This means only the APIs and features you use will be included in your app and the rest will be removed when you compile your app.

Platform Support

Xamarin.Essentials supports the following platforms and operating systems:

Platform     Version

Android     4.4 (API 19) or higher
iOS            10.0 or higher
UWP    10.0.16299.0 or higher

Prerequisites
  • Visual Studio 2017(Windows or Mac)
Setting up a Xamarin.Forms Project


Start by creating a new Xamarin.Forms project.  you’ll learn more by going through the steps yourself.
Choose the Xamarin.Forms App Project type under Cross-platform/App in the New Project dialog.



Name your app, select “Use Portable Class Library” for shared code, and target both Android and iOS.



You probably want your project and solution to use the same name as your app. Put it in your preferred folder for projects and click Create.



You now have a basic Xamarin.Forms app. Click the play button to try it out.



Setting up the User Interface

Go to MainPage.Xaml and write the following code.

MainPage.xaml

Add Xamarin Essentials

In this step, add Xamarin.Essentials to your project. You can install Xamarin.Essentials via NuGet, or you can browse the source code on GitHub.

Go to Solution Explorer and select your solution. Right-click and select "Manage NuGet Packages for Solution". Search "Xamarin.Essentials" and add Package. Remember to install it for each project (PCL, Android, iO, and UWP).





Xamarin.Essentials requires platform-specific setup

Android

Xamarin.Essentials supports a minimum Android version of 4.4, corresponding to API level 19, but the target Android version for compiling must be 8.1, corresponding to API level 27. (In Visual Studio, these two versions are set in the Project Properties dialog for the Android project, in the Android Manifest tab. In Visual Studio for Mac, they're set in the Project Options dialog for the Android project, in the Android Application tab.)

Xamarin.Essentials installs version 27.0.2 of the Xamarin.Android.Support libraries that it requires. Any other Xamarin.Android.Support libraries that your application requires should also be updated to version 27.0.2 using the NuGet package manager. All Xamarin.Android.Support libraries used by your application should be the same, and should be at least version 27.0.2. Refer to the troubleshooting page if you have issues adding the Xamarin.Essentials NuGet or updating NuGets in your solution.

In the Android project's MainLauncher or any Activity that is launched Xamarin.Essentials must be initialized in the OnCreate method:

To handle runtime permissions on Android, Xamarin.Essentials must receive any OnRequestPermissionsResult. Add the following code to all Activity classes:


iOS

No additional setup required.

UWP

No additional setup required.


In this step, write the following code for get Device Information.


MainPage.xaml.cs

using Xamarin.Forms;
using Xamarin.Essentials;
namespace XamarinEssentials
{
 public partial class MainPage : ContentPage
 {
  public MainPage()
  {
   InitializeComponent();
             
            lblDeviceName.Text ="Device Name :"+ DeviceInfo.Name;
            lblDeviceType.Text ="DeviceType :"+ DeviceInfo.DeviceType.ToString();
            lblModel.Text ="Model :"+ DeviceInfo.Model;
            lblManufacturer.Text ="Manufacturer :" + DeviceInfo.Manufacturer;
            lblPlatform.Text ="Platform : " + DeviceInfo.Platform;
            lblVersion.Text = "Version :" + DeviceInfo.Version;
  }
 }
}



Click the play button to try it out.



I hope you have understood how to get DeviceInfo Using Xamarin Essentials in Xamarin.Forms.
Thanks for reading. Please share comments and feedback.
Delpin Susai Raj Tuesday 3 July 2018

Getting Started With Visual Studio Mobile Center In Xamarin iOS

In this blog, you will learn how to Create a Crash Report Using Visual Studio Mobile Center 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.

Visual Studio Mobile Center is mission control for your mobile apps
Bring your apps written in any language to Visual Studio Mobile Center’s cloud and lifecycle services and you’ll get faster release cycles, higher-quality apps, and the time and data to focus on what users want.Learn More 


Prerequisites


  • Xamarin Studio.
  • Xcode.
  • Mobile Center Account


The steps given below are required to be followed in order to Create a Crash Report Using Visual Studio Mobile Center in Xamarin iOS, using Xamarin Studio.


Go to This link https://mobile.azure.com and log in with your credential


Step 1

After Login mobile center.Create a New App in Mobile Center site.

Add New—> Add New app.



Step 2

In this step Give your app Name(Ex:XamainiosCrashreport) and Description.

OS           :iOS
Platform :Xamarin

Afterwards, click Add New App.




Step 3

In this step go to Manage App and general information copy your app secret key.



Step 4

Go To Xamarin Studio.
Click New Solution—> select iOS—>select App--> Choose single View App. Afterwards, click Next.




Step 5

In this step, configure your app. Give the app name (Ex:sample), Organization Identifier. Afterwards, click Next.



Step 6

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



Step 7

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 8

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



Step 9

In this step design your app.using storyboard and Toolbox.

  1. Button(btnCrash)




Step 10

In this step add Two Package in your project.


  1. Mobile Center
  2. Mobile Center Crashes


Go to Solution Explorer—>Package—>Add Package.

Now Choose Mobile Center,Mobile Center Crashes and select Version. Afterwards, click Add Package.



Step 11

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

ViewController.cs

using System;

using UIKit;

using Microsoft.Azure.Mobile;
using Microsoft.Azure.Mobile.Crashes;
namespace XamariniOSCrashReport
{
 public partial class ViewController : UIViewController
 {
  public const string MOBILE_CENTER_ID= "8f7b790d-cafc-4555-ad29-5a784375ac89";
  protected ViewController(IntPtr handle) : base(handle)
  {
   // Note: this .ctor should not contain any initialization logic.
  }

  public override void ViewDidLoad()
  {
   base.ViewDidLoad();
   MobileCenter.Start(MOBILE_CENTER_ID, typeof(Crashes));
   // Perform any additional setup after loading the view, typically from a nib.
  }

  partial void BtnClick_TouchUpInside(UIButton sender)
  {
   throw new NotImplementedException("Not Implement Exception");
  }

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





Step 12

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.



You can click button App will be Crash.



Now you can Go to the Mobile Center your app crash tab,The Crash Report will writen Successfully.



Summary

This was the process of how to Create a Crash Report Using Visual Studio Mobile Center in Xamarin iOS , using Xamarin Studio.