Bläddra i källkod

Cancel multiple notifications at once (iOS)

Sebastián Katzer 11 år sedan
förälder
incheckning
9bcabe5af9
3 ändrade filer med 31 tillägg och 26 borttagningar
  1. 1 1
      CHANGELOG.md
  2. 12 6
      src/ios/APPLocalNotification.m
  3. 18 19
      www/local-notification.js

+ 1 - 1
CHANGELOG.md

@@ -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)

+ 12 - 6
src/ios/APPLocalNotification.m

@@ -93,16 +93,22 @@
 - (void) cancel:(CDVInvokedUrlCommand*)command
 {
     [self.commandDelegate runInBackground:^{
-        NSString* id = [[command arguments]
+        NSArray* ids = [[command arguments]
                         objectAtIndex:0];
 
-        UILocalNotification* notification;
+        for (NSString* id in ids) {
+            UILocalNotification* notification;
 
-        notification = [[UIApplication sharedApplication]
-                        scheduledLocalNotificationWithId:id];
+            notification = [[UIApplication sharedApplication]
+                            scheduledLocalNotificationWithId:id];
+
+            if (!notification)
+                continue;
+
+            [self cancelLocalNotification:notification];
+            [self fireEvent:@"cancel" localNotification:notification];
+        }
 
-        [self cancelLocalNotification:notification];
-        [self fireEvent:@"cancel" localNotification:notification];
         [self execCallback:command];
     }];
 }

+ 18 - 19
www/local-notification.js

@@ -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);
 };