Native APIs | Native UI: Scripting
This section provides a guide to work with Native UI scripting API.
You can access the Native UI module API via the NativeUI class under the EasyMobile namespace.
Alerts
Alerts are available on both iOS and Android platform and can have up to three buttons.
Simple (one-button) alerts are useful in giving the user contextual information. To show a simple alert with the default OK button, you only need to provide a title and a message for the alert:
// Show a simple alert with OK button
NativeUI.AlertPopup alert = NativeUI.Alert("Sample Alert", "This is a sample alert with an OK button.");
You can also show a one-button alert with a custom button label.
// Show an alert with a button labeled as "Got it"
NativeUI.AlertPopup alert = NativeUI.Alert(
"Sample Alert",
"This is a sample alert with a custom button.",
"Got it"
);
Two-button alerts can be useful when needing to ask for user confirmation. To show a two-button alert, you need to specify the labels of these two buttons.
// Show a two-button alert with the buttons labeled as "Button 1" & "Button 2"
NativeUI.AlertPopup alert = NativeUI.ShowTwoButtonAlert(
"Sample Alert",
"This is a two-button alert.",
"Button 1",
"Button 2"
);
Three-button alerts can be used to present the user with several options, a typical usage of it is to implement the Rate Us popup. To show a three-button alert, you need to specify the labels of the three buttons.
// Show a three-button alert with the buttons labeled as "Button 1", "Button 2" & "Button 3"
NativeUI.AlertPopup alert = NativeUI.ShowThreeButtonAlert(
"Sample Alert",
"This is a three-button alert.",
"Button 1",
"Button 2",
"Button 3"
);
Whenever an alert is shown, a NativeUI.AlertPopup object is returned, when the alert is closed, this object will fire an OnComplete event and then destroy itself. The argument of this event is the index of the clicked button. You should listen to this event and take appropriate action depending on the button selected.
// Show a three button alert and handle its OnComplete event
NativeUI.AlertPopup alert = NativeUI.ShowThreeButtonAlert(
"Sample Alert",
"This is a three-button alert.",
"Button 1",
"Button 2",
"Button 3"
);
// Subscribe to the event
if (alert != null)
{
alert.OnComplete += OnAlertCompleteHandler;
}
// The event handler
void OnAlertCompleteHandler(int buttonIndex)
{
switch (buttonIndex)
{
case 0:
// Button 1 was clicked
break;
case 1:
// Button 2 was clicked
break;
case 2:
// Button 3 was clicked
break;
default:
break;
}
}
Only one alert popup can be shown at a time. Any call to show an alert while another one is being displayed will be ignored. You can check if an alert is being shown using the IsShowingAlert method.
// Check if an alert is being displayed.
bool isShowingAlert = NativeUI.IsShowingAlert();
Toasts
Toast is a short message displayed at the bottom of the screen and automatically disappears after a timeout. Toasts are available only on Android platform. To show a toast message:
// Show a sample toast message
NativeUI.ShowToast("This is a sample Android toast");