Skip to content

06. Clear

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

Clearing local notifications is possible when they are triggered and present in the notification center. Clearing a not yet triggered local notification takes no effect.

Semantic

If you clear a scheduled local notification, it will be cleared out from the notification center. But will trigger in future if not yet triggered or repeating.

Interface

The plugin provides clear() to clear a single or multiple local notifications and clearAll() to clear all triggered notifications.

The clear 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 clearAll 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.clear(1, function() {
    alert("done");
});

Multiple notifications

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

All notifications

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

Events

There are two event types to get informed when a local notification has been cleared. The clear event will be fired for each local notification if you call clear(). The clearall event behaves analog to the clearAll() interface.

clear Event

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

clearall Event

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

Further Informations

Use getTriggeredIds() to find out which local notifications have been triggered and are available from clearing out from the notification center.

The following example is equivalent to clearAll():

cordova.plugins.notification.local.getTriggeredIds(function(ids) {
    notification.local.clear(ids);
}, cordova.plugins);