-
Notifications
You must be signed in to change notification settings - Fork 1.8k
09. Events
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.
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. |
- The
click
event will also be called after deviceready if the app wasn't running. - The
clear
andclearall
event will not be called when done from outside the app on iOS.
To get informed about events, a listener for that event needs to be declared as following through the on()
interface. Multiple listener for one event are supported.
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)
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.