Skip to content

07. Cancelation

Sebastián Katzer edited this page Mar 5, 2015 · 2 revisions

Cancelation of local notifications is possible as long as they haven't been triggered or if they have a repeating interval. Cancel a triggered local notification is equivalent to clear them.

Semantic

If you cancel a scheduled local notification, it will ...

  • not be triggered anymore
  • be cleared out from the notification center

Interface

The plugin provides cancel() to cancel a single or multiple local notifications and cancelAll() to cancel all scheduled or triggered local 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.

Single notification

cordova.plugins.notification.local.cancel(1, function() {
    alert("done");
});

Multiple notifications

cordova.plugins.notification.local.cancel([1, 2], function() {
    alert("done");
});

All notifications

cordova.plugins.notification.local.cancelAll(function() {
    alert("done");
}, this);

Events

There are two event types to get informed when a local notification has been canceled. The cancel event will be fired for each local notification if you call cancel(). The cancelall event behaves analog to the cancelAll() interface.

cancel Event

cordova.plugins.notification.local.on("cancel", function(notification) {
    alert("canceled: " + notification.id);
});

cancelall Event

cordova.plugins.notification.local.on("cancelall", function() {
    alert("canceled all");
}, this);

Further Informations

Use getIds() to find out which local 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);