Creating Toast Notification 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 create Toast Notification in Xamarin iOS, using Xamarin Studio.

Step 1

Go To Xamarin Studio.

Click New Solution—> select iOS—>select App--> choose Single View App. Afterwards, click Next.

 

Step 2

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

 

step 3

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

 

Step 4

Subsequently, go to the solution and view 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

In this step, add the Toast Component in your app.

Now, go to the Solution—>Components—>click "Get More Components".

 

Step 7

Now, select All Components, search Toast. Choose Toast for iOS.



Step 8

Now, click "Add to App". The component will be added in your app.

 

Step 9

Now, go to the toolbox window and scroll down to drag and drop the Button.

Next, you need to align the Button, using constraints.

 

Step 10

Now, go to the properties window. Select the Button and give a name (Ex:btnShowToast).

 

Step 11

In this step, go to the ViewController.cs page and add the namespace as given below.

ViewController.cs

using ToastIOS;

 

Step 12

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

ViewController.cs
  1. namespace XamariniOSToastNotification  
  2. {  
  3.     public partial class ViewController: UIViewController {  
  4.         protected ViewController(IntPtr handle): base(handle) {  
  5.             // Note: this .ctor should not contain any initialization logic.  
  6.         }  
  7.         public override void ViewDidLoad() {  
  8.             base.ViewDidLoad();  
  9.             // Perform any additional setup after loading the view, typically from a nib.  
  10.         }  
  11.         partial void BtnDefault_TouchUpInside(UIButton sender) {  
  12.             Toast.MakeText("Hello Xamarin iOS").Show();  
  13.         }  
  14.         public override void DidReceiveMemoryWarning() {  
  15.             base.DidReceiveMemoryWarning();  
  16.             // Release any cached data, images, etc that aren't in use.  
  17.         }  
  18.     }  
  19. }  


Step 13

Now, go to Run option. Choose "Debug" and from the list of iPhone and iPad simulators, you can choose any 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 "Show Toast" button. Toast will be working successfully.

 

Summary

This was the process of creating the Toast Notification in Xamarin iOS , using Xamarin Studio.


Similar Articles