Commit cbf00120 by Sebastián Katzer

Callbacks for `cancel` & `cancelAll`

parent 5c10b767
## ChangeLog
#### Version 0.8.0 (not yet released)
- [enhancement:] android 2.1 support added (Thanks to **khizarsonu**)
- [enhancement:] Android 2.x (SDK >= 7) support (Thanks to **khizarsonu**)
- [enhancement:] Scope parameter for `isScheduled` and `getScheduledIds`
- [enhancement:] Callbacks for `cancel` & `cancelAll`
#### Version 0.7.4 (22.03.2014)
- [bugfix:] Platform specific properties were ignored.
......
......@@ -70,8 +70,9 @@ More informations can be found [here][PGB_plugin].
## ChangeLog
#### Version 0.8.0 (not yet released)
- [enhancement:] android 2.1 support added (Thanks to **khizarsonu**)
- [enhancement:] Android 2.x (SDK >= 7) support (Thanks to **khizarsonu**)
- [enhancement:] Scope parameter for `isScheduled` and `getScheduledIds`
- [enhancement:] Callbacks for `cancel` & `cancelAll`
#### Further informations
- See [CHANGELOG.md][changelog] to get the full changelog for the plugin.
......@@ -131,7 +132,9 @@ Note that only local notifications with an ID can be canceled.
- See [getScheduledIds][getscheduledids] of how to retrieve a list of IDs of all scheduled local notifications.
```javascript
window.plugin.notification.local.cancel(ID);
window.plugin.notification.local.cancel(ID, function () {
// The notification has been canceled
}, scope);
```
### Cancel all scheduled local notifications
......@@ -142,7 +145,9 @@ The method cancels all local notifications even if they have no ID.
- See the [oncancel][oncancel] event of how a listener can be registered to be notified when a local notification has been canceled.
```javascript
window.plugin.notification.local.cancelAll();
window.plugin.notification.local.cancelAll(function () {
// All notifications have been canceled
}, scope);
```
### Check wether a notification with an ID is scheduled
......
......@@ -67,7 +67,7 @@ public class LocalNotification extends CordovaPlugin {
}
@Override
public boolean execute (String action, final JSONArray args, CallbackContext callbackContext) throws JSONException {
public boolean execute (String action, final JSONArray args, final CallbackContext command) throws JSONException {
if (action.equalsIgnoreCase("add")) {
cordova.getThreadPool().execute( new Runnable() {
public void run() {
......@@ -78,8 +78,6 @@ public class LocalNotification extends CordovaPlugin {
add(options, true);
}
});
return true;
}
if (action.equalsIgnoreCase("cancel")) {
......@@ -89,10 +87,9 @@ public class LocalNotification extends CordovaPlugin {
cancel(id);
unpersist(id);
execCallback(command);
}
});
return true;
}
if (action.equalsIgnoreCase("cancelAll")) {
......@@ -100,24 +97,19 @@ public class LocalNotification extends CordovaPlugin {
public void run() {
cancelAll();
unpersistAll();
execCallback(command);
}
});
return true;
}
if (action.equalsIgnoreCase("isScheduled")) {
String id = args.optString(0);
isScheduled(id, callbackContext);
return true;
isScheduled(id, command);
}
if (action.equalsIgnoreCase("getScheduledIds")) {
getScheduledIds(callbackContext);
return true;
getScheduledIds(command);
}
if (action.equalsIgnoreCase("deviceready")) {
......@@ -126,24 +118,17 @@ public class LocalNotification extends CordovaPlugin {
deviceready();
}
});
return true;
}
if (action.equalsIgnoreCase("pause")) {
isInBackground = true;
return true;
}
if (action.equalsIgnoreCase("resume")) {
isInBackground = false;
return true;
}
// Returning false results in a "MethodNotFound" error.
return false;
return true;
}
/**
......@@ -310,6 +295,13 @@ public class LocalNotification extends CordovaPlugin {
}
/**
* Simply invokes the callback without any parameter.
*/
private static void execCallback (CallbackContext command) {
command.sendPluginResult(new PluginResult(PluginResult.Status.OK));
}
/**
* Fires the given event.
*
* @param {String} event The Name of the event
......
......@@ -53,6 +53,8 @@
- (NSString*) applicationState;
// Retrieves all scheduled notifications
- (NSArray*) scheduledNotifications;
// Simply invokes the callback without any parameter
- (void) execCallback:(CDVInvokedUrlCommand*)command;
// Fires the given event
- (void) fireEvent:(NSString*)event id:(NSString*)id json:(NSString*)json;
......@@ -133,6 +135,8 @@
if (notification) {
[self cancelNotification:notification fireEvent:YES];
}
[self execCallback:command];
}];
}
......@@ -153,6 +157,8 @@
[[UIApplication sharedApplication]
setApplicationIconBadgeNumber:0];
[self execCallback:command];
}];
}
......@@ -561,6 +567,18 @@
}
/**
* Simply invokes the callback without any parameter.
*/
- (void) execCallback:(CDVInvokedUrlCommand*)command
{
CDVPluginResult *result = [CDVPluginResult
resultWithStatus:CDVCommandStatus_OK];
[self.commandDelegate sendPluginResult:result
callbackId:command.callbackId];
}
/**
* Fires the given event.
*
* @param {NSString} event
......
......@@ -84,6 +84,7 @@ namespace Cordova.Extension.Commands
cancelAll(jsonArgs);
FireEvent("cancel", notificationID, "");
DispatchCommandResult();
}
/// <summary>
......
......@@ -167,18 +167,30 @@ LocalNotification.prototype = {
*
* @param {String} id
* The ID of the notification
* @param {Function} callback
* A function to be called after the notification has been canceled
* @param {Object} scope
* The scope for the callback function
*/
cancel: function (id) {
var id = id.toString();
cancel: function (id, callback, scope) {
var id = id.toString(),
callbackFn = this.createCallbackFn(callback, scope);
cordova.exec(null, null, 'LocalNotification', 'cancel', [id]);
cordova.exec(callbackFn, null, 'LocalNotification', 'cancel', [id]);
},
/**
* Removes all previously registered notifications.
*
* @param {Function} callback
* A function to be called after all notifications have been canceled
* @param {Object} scope
* The scope for the callback function
*/
cancelAll: function () {
cordova.exec(null, null, 'LocalNotification', 'cancelAll', []);
cancelAll: function (callback, scope) {
var callbackFn = this.createCallbackFn(callback, scope);
cordova.exec(callbackFn, null, 'LocalNotification', 'cancelAll', []);
},
/**
......
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