Bläddra i källkod

Invoke callback for schedule/update with boolean arg if the permission
is granted [Fixes #1187]

Sebastián Katzer 8 år sedan
förälder
incheckning
c88dd6ecc1

+ 2 - 2
src/android/LocalNotification.java

@@ -142,11 +142,11 @@ public class LocalNotification extends CordovaPlugin {
                 } else
                 if (action.equalsIgnoreCase("schedule")) {
                     schedule(args);
-                    command.success();
+                    check(command);
                 } else
                 if (action.equals("update")) {
                     update(args);
-                    command.success();
+                    check(command);
                 } else
                 if (action.equals("cancel")) {
                     cancel(args);

+ 6 - 4
src/ios/APPLocalNotification.m

@@ -101,7 +101,7 @@
             [self scheduleNotification:notification];
         }
 
-        [self execCallback:command];
+        [self check:command];
      }];
 }
 
@@ -131,8 +131,8 @@
 
             [self fireEvent:@"update" notification:notification];
         }
-
-        [self execCallback:command];
+        
+        [self check:command];
     }];
 }
 
@@ -613,7 +613,9 @@
 }
 
 /**
- * Simply invokes the callback without any parameter.
+ * Invokes the callback without any parameter.
+ *
+ * @return [ Void ]
  */
 - (void) execCallback:(CDVInvokedUrlCommand*)command
 {

+ 2 - 2
src/windows/LocalNotificationProxy.js

@@ -107,7 +107,7 @@ exports.schedule = function (success, error, args) {
         exports.fireEvent('add', toast);
     }
 
-    success();
+    exports.check(success, error);
 };
 
 /**
@@ -133,7 +133,7 @@ exports.update = function (success, error, args) {
         exports.fireEvent('update', toast);
     }
 
-    success();
+    exports.check(success, error);
 };
 
 /**

+ 12 - 7
www/local-notification-core.js

@@ -61,11 +61,13 @@ exports.requestPermission = function (callback, scope) {
  */
 exports.schedule = function (msgs, callback, scope, args) {
     var fn = function (granted) {
-
-        if (!granted) return;
-
         var toasts = this.toArray(msgs);
 
+        if (!granted && callback) {
+            callback.call(scope || this, false);
+            return;
+        }
+
         for (var toast of toasts) {
             this.mergeWithDefaults(toast);
             this.convertProperties(toast);
@@ -93,13 +95,16 @@ exports.schedule = function (msgs, callback, scope, args) {
  */
 exports.update = function (msgs, callback, scope, args) {
     var fn = function(granted) {
-
-        if (!granted) return;
-
         var toasts = this.toArray(msgs);
 
+        if (!granted && callback) {
+            callback.call(scope || this, false);
+            return;
+        }
+
         for (var toast of toasts) {
-            this.convertProperties(toast);        }
+            this.convertProperties(toast);
+        }
 
         this.exec('update', toasts, callback, scope);
     };