notification by Trigger.io

Currently displaying version

notification: Notifications

The forge.notification namespace allows you to alert the user through various channels while the app is the foreground.

Note: to push notifications to users even if the app is not in focus, you can use the parse module.

API

forge.notification.create(title, text, success, error)

iOS, Android

On Android, add a notification to the device's status bar: when it's tapped, the success callback is invoked. On iOS, a native alert-style popup is shown, and your success callback is invoked when it is cleared.

Parameters:
title
string title
text
string notification message
success
function() called when the user taps on the notification in the statusbar, or dismisses the alert
error
function(content) called with details of any error which may occur

forge.notification.setBadgeNumber(number, success, error)

iOS

Allows you to set or remove a badge for your app's icon on the iOS home screen.

Parameters:
number
integer number
success
function() callback to be invoked when no errors occur
error
function(content) called with details of any error which may occur

Note: If you pass in 0 as number, it will remove this badge. This is particularly useful if you want to clear a badge set by a push notification.

Badge number

forge.notification.getBadgeNumber(success, error)

iOS

Allows you to get the badge number for your app's icon on the iOS home screen.

Parameters:
success
function(integer) callback to be invoked when no errors occur (argument is the current badge number)
error
function(content) called with details of any error which may occur

forge.notification.alert(title, text, success, error)

iOS, Android

Show a dialog window with text content that the user can dismiss. Similar to using window.alert except you can control the title text for the dialog.

Parameters:
title
string title
text
string notification message
success
function() called when the user dismisses the alert
error
function(content) called with details of any error which may occur

Native alert dialog

forge.notification.confirm(title, body, positive, negative, success, error)

iOS, Android

Show a dialog window prompting the user with a "yes"/"no" style question.

Parameters:
title
string text to show as the title of the dialog
body
string text to show as the body of the dialog
positive
string text to use for the positive action button
negative
string text to use for the negative action button
success
function(result) called with true if the user selected the positive option, false if they selected the negative option
error
function(content) called with details of any error which may occur

Example:

Native confirm dialog

forge.notification.confirm("My Title: Confirm", "My Body: Confirm", "Y", "N", 
    function (userClickedYes) {
      if (userClickedYes) {
        // ... implement logic for when user clicked "Y"
      } else {
        // ... implement logic for when user clicked "N"
      }
});

forge.notification.toast(body, success, error)

iOS, Android

Create a small popup which disappears after a few seconds.

Parameters:
body
string text to show as the body of the dialog
success
function() called if the toast is displayed successfully
error
function(content) called with details of any error which may occur

Native toast

forge.notification.showLoading(title, body, success, error)

iOS, Android

Show a loading spinner in front of the webview, must be hidden with forge.notification.hideLoading(). Repeated calls to showLoading will update the title and body on the shown loading dialog.

Parameters:
title
string loading dialog title
body
string text to show as the body of the dialog
success
function() called if the loading dialog is displayed successfully
error
function(content) called with details of any error which may occur

forge.notification.hideLoading(success, error)

iOS, Android

Hide any loading dialog shown with forge.notification.showLoading().

Parameters:
success
function() called if the loading dialog is hidden successfully
error
function(content) called with details of any error which may occur

Permissions

On Android this module will add the VIBRATE permission.