Commit 9bcabe5a by Sebastián Katzer

Cancel multiple notifications at once (iOS)

parent 0840fb0e
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
- [enhancement:] Callbacks for `add`, `cancel` & `cancelAll` - [enhancement:] Callbacks for `add`, `cancel` & `cancelAll`
- [enhancement:] `image:` accepts remote URLs and local URIs (Android) - [enhancement:] `image:` accepts remote URLs and local URIs (Android)
- [enhancement:] Schedule multiple notifications at once (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 multiple notifications at once (Android)
- [enhancement:] `clear` & `clearAll` methods (Android) - [enhancement:] `clear` & `clearAll` methods (Android)
- [enhancement:] `onclear` event (Android) - [enhancement:] `onclear` event (Android)
......
...@@ -93,16 +93,22 @@ ...@@ -93,16 +93,22 @@
- (void) cancel:(CDVInvokedUrlCommand*)command - (void) cancel:(CDVInvokedUrlCommand*)command
{ {
[self.commandDelegate runInBackground:^{ [self.commandDelegate runInBackground:^{
NSString* id = [[command arguments] NSArray* ids = [[command arguments]
objectAtIndex:0]; objectAtIndex:0];
UILocalNotification* notification; for (NSString* id in ids) {
UILocalNotification* notification;
notification = [[UIApplication sharedApplication] notification = [[UIApplication sharedApplication]
scheduledLocalNotificationWithId:id]; scheduledLocalNotificationWithId:id];
if (!notification)
continue;
[self cancelLocalNotification:notification];
[self fireEvent:@"cancel" localNotification:notification];
}
[self cancelLocalNotification:notification];
[self fireEvent:@"cancel" localNotification:notification];
[self execCallback:command]; [self execCallback:command];
}]; }];
} }
......
...@@ -172,19 +172,28 @@ exports.clearAll = function (callback, scope) { ...@@ -172,19 +172,28 @@ exports.clearAll = function (callback, scope) {
}; };
/** /**
* Cancels the specified notification. * Cancels the specified notifications.
* *
* @param {String} id * @param {String[]} ids
* The ID of the notification * The IDs of the notifications
* @param {Function} callback * @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 * @param {Object} scope
* The scope for the callback function * The scope for the callback function
*/ */
exports.cancel = function (id, callback, scope) { exports.cancel = function (ids, callback, scope) {
var notId = (id || '0').toString();
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) { ...@@ -304,11 +313,7 @@ exports.registerPermission = function (callback, scope) {
* The callback function's scope * The callback function's scope
*/ */
exports.promptForPermission = function (callback, scope) { exports.promptForPermission = function (callback, scope) {
console.warn('Depreated: Please use `notification.local.registerPermission` instead.');
console.warn(
'`notification.local.promptForPermission` is deprecated,',
'please use `notification.local.registerPermission`.'
);
exports.registerPermission.apply(this, arguments); exports.registerPermission.apply(this, arguments);
}; };
...@@ -613,13 +618,7 @@ exports.createCallbackFn = function (callbackFn, scope) { ...@@ -613,13 +618,7 @@ exports.createCallbackFn = function (callbackFn, scope) {
*/ */
exports.exec = function (action, args, callback, scope) { exports.exec = function (action, args, callback, scope) {
var fn = this.createCallbackFn(callback, scope), var fn = this.createCallbackFn(callback, scope),
params = []; params = args ? [args] : [];
if (Array.isArray(args)) {
params = args;
} else if (args) {
params.push(args);
}
exec(fn, null, 'LocalNotification', action, params); exec(fn, null, 'LocalNotification', action, params);
}; };
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment