Skip to content

09. Events

Sebastián Katzer edited this page Mar 3, 2015 · 4 revisions

Events are useful to hook into the life cycle of local notifications to react on user interactions like the click event or to start a workflow on trigger event.

Overview

The following list gives an overview about all supported events. Most events are related to a interface method.

Event Description Further Informations
schedule A notification was scheduled. Schedule local notifications
trigger A notification was triggered. Schedule local notifications
update A notification was updated. Update local notifications
clear A notification was cleared from the notification center. Clear local notifications
clearall All notifications were cleared from the notification center. Clear local notifications
cancel A notification was canceled. Cancel local notifications
cancelall All notification were canceled. Cancel local notifications
click A notification was clicked.

Further information

  • The click event will also be called after deviceready if the app wasn't running.
  • The clearand clearall event will not be called when done from outside the app on iOS.

Interface

To get informed about events, a listener for that event needs to be declared as following through the on() interface.

The interface requires a event name, a callback function and optionally a callback scope as third argument. The callback will be invoked with the related notification and the application's state as a string - foreground or background.

When scheduling multiple notifications at once, the schedule event will be fired for each single notification. Same applies to cancel, update and clear.

cordova.plugins.notification.local.on("click", function (notification, state) {
    alert(notification.id + " was clicked");
}, this)

In contrast the callback for clearall and cancelall event will be invoked with only the application's state as argument.

cordova.plugins.notification.local.on("clearall", function (state) {
    if (state == "background") {    
        alert("Notification center cleared from outside");
    }
}, this)

Quirks

When scheduling multiple notifications at once, the schedule and trigger events may come in random order due to the asynchronous behavior of the plugin and OS.

Clone this wiki locally