Commit cbe4f5ba by Sebastián Katzer

Schedule multiple notifications at once (iOS)

parent 9bcabe5a
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
- [enhancement:] Scope parameter for `isScheduled` and `getScheduledIds` - [enhancement:] Scope parameter for `isScheduled` and `getScheduledIds`
- [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
- [enhancement:] Cancel multiple notifications at once - [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)
......
...@@ -62,41 +62,38 @@ ...@@ -62,41 +62,38 @@
} }
/** /**
* Schedule a new local notification. * Schedule a set of notifications.
* *
* @param properties * @param properties
* A dict of properties * A dict of properties for each notification
*/ */
- (void) add:(CDVInvokedUrlCommand*)command - (void) add:(CDVInvokedUrlCommand*)command
{ {
[self.commandDelegate runInBackground:^{ [self.commandDelegate runInBackground:^{
NSDictionary* options = [[command arguments] for (NSDictionary* options in command.arguments) {
objectAtIndex:0]; UILocalNotification* notification;
UILocalNotification* notification; notification = [[UILocalNotification alloc]
initWithOptions:options];
notification = [[UILocalNotification alloc] [self scheduleLocalNotification:notification];
initWithOptions:options]; [self fireEvent:@"add" localNotification:notification];
}
[self scheduleLocalNotification:notification];
[self fireEvent:@"add" localNotification:notification];
[self execCallback:command]; [self execCallback:command];
}]; }];
} }
/** /**
* Cancels a given local notification. * Cancel a set of notifications.
* *
* @param id * @param ids
* The ID of the local notification * The IDs of the notifications
*/ */
- (void) cancel:(CDVInvokedUrlCommand*)command - (void) cancel:(CDVInvokedUrlCommand*)command
{ {
[self.commandDelegate runInBackground:^{ [self.commandDelegate runInBackground:^{
NSArray* ids = [[command arguments] for (NSString* id in command.arguments) {
objectAtIndex:0];
for (NSString* id in ids) {
UILocalNotification* notification; UILocalNotification* notification;
notification = [[UIApplication sharedApplication] notification = [[UIApplication sharedApplication]
......
...@@ -104,29 +104,28 @@ exports.setDefaults = function (newDefaults) { ...@@ -104,29 +104,28 @@ exports.setDefaults = function (newDefaults) {
* A function to be called after the notification has been canceled * A function to be called after the notification has been canceled
* @param {Object} scope * @param {Object} scope
* The scope for the callback function * The scope for the callback function
*
* @return {Number}
* The notification's ID
*/ */
exports.add = function (props, callback, scope) { exports.add = function (props, callback, scope) {
var options = this.mergeWithDefaults(props), this.registerPermission(function(granted) {
fn = this.createCallbackFn(callback, scope);
this.convertOptions(options); if (!granted)
return;
if (['WinCE', 'Win32NT'].indexOf(device.platform) > -1) { var notifications = Array.isArray(props) ? props : [props];
fn = function (cmd) {
eval(cmd);
};
}
this.registerPermission(function(granted) { for (var i = 0; i < notifications.length; i++) {
if (granted) { var properties = notifications[i];
this.exec('add', options, callback, scope);
this.mergeWithDefaults(properties);
this.convertProperties(properties);
} }
}, this);
return options.id; if (device.platform != 'iOS') {
notifications = notifications[0];
}
this.exec('add', notifications, callback, scope);
}, this);
}; };
/** /**
...@@ -519,7 +518,7 @@ exports.mergeWithDefaults = function (options) { ...@@ -519,7 +518,7 @@ exports.mergeWithDefaults = function (options) {
* @retrun {Object} * @retrun {Object}
* The converted property list * The converted property list
*/ */
exports.convertOptions = function (options) { exports.convertProperties = function (options) {
if (options.id) { if (options.id) {
options.id = options.id.toString(); options.id = options.id.toString();
} }
...@@ -618,7 +617,13 @@ exports.createCallbackFn = function (callbackFn, scope) { ...@@ -618,7 +617,13 @@ 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 = args ? [args] : []; params = [];
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