Skip to content

08. Querying

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

Querying local notifications can be useful if you need to know for example if a certain event was triggered or is still pending. If a special local notification is still present in the notification center or to get the notifications properties for future updates.

Semantic

The plugin provides interfaces to query for the presence of local notifications, their IDs and properties depend on the state.

A local notification's state can be scheduled or triggered.

  • Scheduled means that the local notification was scheduled but not yet triggered and added to the notification center. Repeating local notifications are always in that state.
  • Triggered means the event has occurred and the local notification is added to the notification center.

Interface

Querying for existence of a single local notification can be done through isPresent(), isScheduled() and isTriggered(). They take a number to indicate the notification ID and a callback function and a scope as second and third argument. The callback will be invoked with a boolean to indicate if the local notification with the state could be found.

Querying ID's is possible through the interfaces getAllIds(), getScheduledIds() and getTriggeredIds(). They take a callback function and a scope as arguments. The callback will be invoked with an array of all IDs state independent or all IDs for given state.

Querying for properties is possible through the interfaces get(), getAll(), getScheduled() and getTriggered(). They take a number to indicate the notification ID or an array of numbers and a callback function and a scope as second and third argument. The callback will be invoked with a hash or array of hashed. All three methods can also be called without an ID.

Check Presence

cordova.plugins.notification.local.isPresent(1, function (present) {
    alert(present ? "present" : "not found");
});

or dependent on state:

cordova.plugins.notification.local.is[Scheduled|Triggered](1, function (present) {
    // isScheduled() or isTriggered()
});

Get IDs

cordova.plugins.notification.local.getAllIds(function (ids) {
    // getIds() as alias can also be used!
});

or dependent on state:

cordova.plugins.notification.local.get[Scheduled|Triggered]Ids(function (ids) {
    // getScheduledIds() or getTriggeredIds()
});

Get single Notifications

cordova.plugins.notification.local.get(1, function (notifications) {
    alert(notification.text);
});

or dependent on state:

cordova.plugins.notification.local.get[Scheduled|Triggered](1, function (notifications) {
    // getScheduled() or getTriggered()
});

Get multiple Notifications

cordova.plugins.notification.local.get([1, 2], function (notifications) {

});

or dependent on state:

cordova.plugins.notification.local.get[Scheduled|Triggered]([1, 2], function (notifications) {
    // getScheduled() or getTriggered()
});

Get All Notifications

cordova.plugins.notification.local.getAll(function (notifications) {
    
});

or dependent on state:

cordova.plugins.notification.local.get[Scheduled|Triggered](function (notifications) {
    // getScheduled() or getTriggered()
});