-
Notifications
You must be signed in to change notification settings - Fork 1.8k
07. Cancelation
Cancelation of notifications is possible as long as they haven't been triggered or if they have a repeating interval. Cancel a triggered notification is equivalent to clear them.
If you cancel a scheduled local notification, it will ...
- not be triggered anymore
- be cleared out from the notification center
The plugin provides cancel()
to cancel a single or multiple notifications and cancelAll()
to cancel all scheduled or triggered notifications.
The cancel interface requires a single notification ID or an array of IDs and optionally a callback function and a scope as second and third argument. The default scope does point to the window object.
The cancelAll interface requires no argument or optionally a callback function and a scope as arguments. The default scope does point to the window object.
cordova.plugins.notification.local.cancel(1, function() {
alert("done");
});
cordova.plugins.notification.local.cancel([1, 2], function() {
alert("done");
});
cordova.plugins.notification.local.cancelAll(function() {
alert("done");
}, this);
There are two event types to get informed when a notification has been canceled. The cancel
event will be fired for each notification if you call cancel(). The cancelall
event behaves analog to the cancelAll() interface.
cordova.plugins.notification.local.on("cancel", function(notification) {
alert("canceled: " + notification.id);
});
cordova.plugins.notification.local.on("cancelall", function() {
alert("canceled all");
}, this);
Use getIds()
to find out which notifications have been already triggered or are scheduled and are available for canceling from the notification manager.
The following example is equivalent to cancelAll():
cordova.plugins.notification.local.getIds(function(ids) {
notification.local.cancel(ids);
}, cordova.plugins);