-
Notifications
You must be signed in to change notification settings - Fork 1.8k
06. Clear
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.
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.
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.
cordova.plugins.notification.local.clear(1, function() {
alert("done");
});
cordova.plugins.notification.local.clear([1, 2], function() {
alert("done");
});
cordova.plugins.notification.local.clearAll(function() {
alert("done");
}, this);
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.
cordova.plugins.notification.local.on("clear", function(notification) {
alert("cleared: " + notification.id);
});
cordova.plugins.notification.local.on("clearall", function() {
alert("cleared all");
}, this);
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);