Commit 7fc01db0 authored by Sebastián Katzer's avatar Sebastián Katzer
Browse files

Add scope parameter for `isScheduled` and `getScheduledIds`

parent afd6a480
Loading
Loading
Loading
Loading
+4 −4
Changes for README.md: 4 added lines, 4 removed lines.
Original line number Diff line number Diff line
@@ -146,7 +146,7 @@ window.plugin.notification.local.cancelAll();

### Check wether a notification with an ID is scheduled
To check if a notification with an ID is scheduled, the `notification.local.isScheduled` interface can be used.<br>
The method takes the ID of the local notification as an argument and a callback function to be called with the result.
The method takes the ID of the local notification as an argument and a callback function to be called with the result. Optional the scope of the callback can be assigned too.

#### Further informations
- See [getScheduledIds][getscheduledids] of how to retrieve a list of IDs of all scheduled local notifications.
@@ -154,17 +154,17 @@ The method takes the ID of the local notification as an argument and a callback
```javascript
window.plugin.notification.local.isScheduled(id, function (isScheduled) {
    // console.log('Notification with ID ' + id + ' is scheduled: ' + isScheduled);
});
}, scope);
```

### Retrieve the IDs from all currently scheduled local notifications
To retrieve the IDs from all currently scheduled local notifications, the `notification.local.isScheduled` interface can be used.<br>
The method takes a callback function to be called with the result as an array of IDs.
The method takes a callback function to be called with the result as an array of IDs. Optional the scope of the callback can be assigned too.

```javascript
window.plugin.notification.local.getScheduledIds(function (scheduledIds) {
    // alert('Scheduled IDs: ' + scheduledIds.join(' ,'));
});
}, scope);
```

### Get the default values of the local notification properties
+31 −5
Changes for www/local-notification.js: 31 added lines, 5 removed lines.
Original line number Diff line number Diff line
@@ -107,6 +107,25 @@ LocalNotification.prototype = {
        return defaults;
    },

    /**
     * @private
     *
     * Creates a callback, which will be executed within a specific scope.
     *
     * @param {Function} callbackFn
     *      The callback function
     * @param {Object} scope
     *      The scope for the function
     *
     * @return {Function}
     *      The new callback function
     */
    createCallbackFn: function (callbackFn, scope) {
        return function () {
            callbackFn.apply(arguments, scope || this);
        }
    },

    /**
     * Add a new entry to the registry
     *
@@ -167,9 +186,13 @@ LocalNotification.prototype = {
     *
     * @param {Function} callback
     *      A callback function to be called with the list
     * @param {Object} scope
     *      The scope for the callback function
     */
    getScheduledIds: function (callback) {
        cordova.exec(callback, null, 'LocalNotification', 'getScheduledIds', []);
    getScheduledIds: function (callback, scope) {
        var callbackFn = this.createCallbackFn(callback, scope);

        cordova.exec(callbackFn, null, 'LocalNotification', 'getScheduledIds', []);
    },

    /**
@@ -179,11 +202,14 @@ LocalNotification.prototype = {
     *      The ID of the notification
     * @param {Function} callback
     *      A callback function to be called with the list
     * @param {Object} scope
     *      The scope for the callback function
     */
    isScheduled: function (id, callback) {
        var id = id.toString();
    isScheduled: function (id, callback, scope) {
        var id         = id.toString(),
            callbackFn = this.createCallbackFn(callback, scope);

        cordova.exec(callback, null, 'LocalNotification', 'isScheduled', [id]);
        cordova.exec(callbackFn, null, 'LocalNotification', 'isScheduled', [id]);
    },

    /**