Use of Toast popup for iOS in phonegap
Posted By : Deepak Rawat | 09-Dec-2014
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
Cookies are important to the proper functioning of a site. To improve your experience, we use cookies to remember log-in details and provide secure log-in, collect statistics to optimize site functionality, and deliver content tailored to your interests. Click Agree and Proceed to accept cookies and go directly to the site or click on View Cookie Settings to see detailed descriptions of the types of cookies and choose whether to accept certain cookies while on the site.
About Author
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.