Use of Toast popup for iOS in phonegap

Posted By : Deepak Rawat | 09-Dec-2014

Use Of Toast Popup For iOS In Phonegap

Toast popup is usually seen in android apps, but we can also use it for iOS apps using phonegap plugin.

 

Toast is a text popup used for showing notifications to user, it doesn’t need any confirmation to close this notification like alert box. With this plugin you can choose where to show the toast and also choose two durations(eg. short and long). To install this plugin in your phonegap/cordova  application write the below code in your CLI:

 

cordova plugin add https://github.com/EddyVerbruggen/Toast-PhoneGap-Plugin.git
 

 

By running the above code the plugin will get installed.

 

Now for showing toast in your phonegap application you have to know where to show the toast(top, center, bottom) and for how long (duration: ‘short’, ‘long’).

 

Use the below code for applying toast in your application:

 

window.plugins.toast.show('yourMessage', ‘duration’, ‘position’ function(a) {
	console.log('toast success: ' + a);
}, function(b) {
	alert('toast error: ' + b);
});

 

 

With the use of this plugin you can also use it like:

 

window.plugins.toast.showShortTop('Hello there!', function(a) {
	console.log('toast success: ' + a);
}, function(b) {
	alert('toast error: ' + b);
});  //this method shows the ‘short’ duration toast at the ‘top’ position. 

 

 

 

Other convenient methods to use toast notification are:

 

  • showShortTop(message)

  • showShortCenter(message)

  • showShortBottom(message)

  • showLongTop(message)

  • showLongCenter(message)

  • showLongBottom(message)

 

Thanks

 

About Author

Author Image
Deepak Rawat

Deepak is a Web and Mobile application Sr. Lead Frontend developer and good working experience with JQuery , AngularJS , Javascript and PhoneGap. His hobbies are listening to music and photography.

Request for Proposal

Name is required

Comment is required

Sending message..