-
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 local notification was scheduled. | Schedule local notifications |
trigger | A local notification was triggered. | Schedule local notifications |
update | A local notification was updated. | Update local notifications |
clear | A local notification was cleared from the notification center. | Clear local notifications |
clearall | All local notifications were cleared from the notification center. | Clear local notifications |
cancel | A local notification was canceled. | Cancel local notifications |
cancelall | All local notification were canceled. | Cancel local notifications |
click | A local 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 local notifications at once, the schedule event will be fired for each single local 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 local notifications at once, the schedule and trigger events may come in random order due to the asynchronous behavior of the plugin and OS.