Commit 9bcabe5a authored by Sebastián Katzer's avatar Sebastián Katzer
Browse files

Cancel multiple notifications at once (iOS)

parent 0840fb0e
Loading
Loading
Loading
Loading
+1 −1
Changes for CHANGELOG.md: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -10,7 +10,7 @@
- [enhancement:] Callbacks for `add`, `cancel` & `cancelAll`
- [enhancement:] `image:` accepts remote URLs and local URIs (Android)
- [enhancement:] Schedule multiple notifications at once (Android)
- [enhancement:] Cancel multiple notifications at once (Android)
- [enhancement:] Cancel multiple notifications at once
- [enhancement:] Clear multiple notifications at once (Android)
- [enhancement:] `clear` & `clearAll` methods (Android)
- [enhancement:] `onclear` event (Android)
+7 −1
Changes for src/ios/APPLocalNotification.m: 7 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -93,16 +93,22 @@
- (void) cancel:(CDVInvokedUrlCommand*)command
{
    [self.commandDelegate runInBackground:^{
        NSString* id = [[command arguments]
        NSArray* ids = [[command arguments]
                        objectAtIndex:0];

        for (NSString* id in ids) {
            UILocalNotification* notification;

            notification = [[UIApplication sharedApplication]
                            scheduledLocalNotificationWithId:id];

            if (!notification)
                continue;

            [self cancelLocalNotification:notification];
            [self fireEvent:@"cancel" localNotification:notification];
        }

        [self execCallback:command];
    }];
}
+18 −19
Changes for www/local-notification.js: 18 added lines, 19 removed lines.
Original line number Diff line number Diff line
@@ -172,19 +172,28 @@ exports.clearAll = function (callback, scope) {
};

/**
 * Cancels the specified notification.
 * Cancels the specified notifications.
 *
 * @param {String} id
 *      The ID of the notification
 * @param {String[]} ids
 *      The IDs of the notifications
 * @param {Function} callback
 *      A function to be called after the notification has been canceled
 *      A function to be called after the notifications has been canceled
 * @param {Object} scope
 *      The scope for the callback function
 */
exports.cancel = function (id, callback, scope) {
    var notId = (id || '0').toString();
exports.cancel = function (ids, callback, scope) {

    ids = Array.isArray(ids) ? ids : [ids];

    for (var i = 0; i < ids.length; i++) {
        ids[i] = ids[i].toString();
    }

    if (device.platform != 'iOS') {
        ids = ids[0];
    }

    this.exec('cancel', notId, callback, scope);
    this.exec('cancel', ids, callback, scope);
};

/**
@@ -304,11 +313,7 @@ exports.registerPermission = function (callback, scope) {
 *      The callback function's scope
 */
exports.promptForPermission = function (callback, scope) {

    console.warn(
        '`notification.local.promptForPermission` is deprecated,',
        'please use `notification.local.registerPermission`.'
    );
    console.warn('Depreated: Please use `notification.local.registerPermission` instead.');

    exports.registerPermission.apply(this, arguments);
};
@@ -613,13 +618,7 @@ exports.createCallbackFn = function (callbackFn, scope) {
 */
exports.exec = function (action, args, callback, scope) {
    var fn = this.createCallbackFn(callback, scope),
        params = [];

    if (Array.isArray(args)) {
        params = args;
    } else if (args) {
        params.push(args);
    }
        params = args ? [args] : [];

    exec(fn, null, 'LocalNotification', action, params);
};