Commit c8ecc570 by Sebastián Katzer

Readded support for update() for iOS

parent 03da779a
...@@ -40,8 +40,8 @@ ...@@ -40,8 +40,8 @@
// Schedule notifications // Schedule notifications
- (void) schedule:(CDVInvokedUrlCommand*)command; - (void) schedule:(CDVInvokedUrlCommand*)command;
//// Update set of notifications // Update set of notifications
//- (void) update:(CDVInvokedUrlCommand*)command; - (void) update:(CDVInvokedUrlCommand*)command;
// Clear notifications by id // Clear notifications by id
- (void) clear:(CDVInvokedUrlCommand*)command; - (void) clear:(CDVInvokedUrlCommand*)command;
// Clear all notifications // Clear all notifications
......
...@@ -104,60 +104,36 @@ ...@@ -104,60 +104,36 @@
}]; }];
} }
///** /**
// * Update a set of notifications. * Update notifications.
// * *
// * @param properties * @param [Array<Hash>] properties A list of key-value properties.
// * A dict of properties for each notification *
// */ * @return [ Void ]
//- (void) update:(CDVInvokedUrlCommand*)command */
//{ - (void) update:(CDVInvokedUrlCommand*)command
// NSArray* notifications = command.arguments; {
// NSArray* notifications = command.arguments;
// [self.commandDelegate runInBackground:^{
// if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"10.0")) { [self.commandDelegate runInBackground:^{
// for (NSDictionary* options in notifications) { for (NSDictionary* options in notifications) {
// NSNumber* id = [options objectForKey:@"id"]; NSNumber* id = [options objectForKey:@"id"];
// UNNotificationRequest* notification; UNNotificationRequest* notification;
//
// notification = [_center getNotificationWithId:id]; notification = [_center getNotificationWithId:id];
//
// if (!notification) if (!notification)
// continue; continue;
//
// // [self updateNotification:[notification copy] [self updateNotification:[notification copy]
// // withOptions:options]; withOptions:options];
// //
// // [self fireEvent:@"update" notification:notification]; [self fireEvent:@"update" notification:notification];
// // }
// // if (notifications.count > 1) {
// // [NSThread sleepForTimeInterval:0.01]; [self execCallback:command];
// // } }];
// } }
// } else {
// for (NSDictionary* options in notifications) {
// NSNumber* id = [options objectForKey:@"id"];
// UILocalNotification* notification;
//
// notification = [_app localNotificationWithId:id];
//
// if (!notification)
// continue;
//
// [self updateLocalNotification:[notification copy]
// withOptions:options];
//
// [self fireEvent:@"update" localnotification:notification];
//
// if (notifications.count > 1) {
// [NSThread sleepForTimeInterval:0.01];
// }
// }
// }
//
// [self execCallback:command];
// }];
//}
/** /**
* Clear notifications by id. * Clear notifications by id.
...@@ -476,36 +452,46 @@ ...@@ -476,36 +452,46 @@
/** /**
* Schedule the local notification. * Schedule the local notification.
*
* @param [ APPNotificationContent* ] notification The notification to schedule.
*
* @return [ Void ]
*/ */
- (void) scheduleNotification:(APPNotificationContent*)notification - (void) scheduleNotification:(APPNotificationContent*)notification
{ {
__weak APPLocalNotification* weakSelf = self; __weak APPLocalNotification* weakSelf = self;
UNNotificationRequest* request = notification.request; UNNotificationRequest* request = notification.request;
NSString* event = [notification.request wasUpdated] ? @"update" : @"add";
[_center addNotificationCategory:notification.category]; [_center addNotificationCategory:notification.category];
[_center addNotificationRequest:request withCompletionHandler:^(NSError* e) { [_center addNotificationRequest:request withCompletionHandler:^(NSError* e) {
__strong APPLocalNotification* strongSelf = weakSelf; __strong APPLocalNotification* strongSelf = weakSelf;
[strongSelf fireEvent:@"add" notification:request]; [strongSelf fireEvent:event notification:request];
}]; }];
} }
///** /**
// * Update the local notification. * Update the local notification.
// */ *
//- (void) updateNotification:(UILocalNotification*)notification * @param [ UNNotificationRequest* ] notification The notification to update.
// withOptions:(NSDictionary*)newOptions * @param [ NSDictionary* ] options The options to update.
//{APPNotificationRequest* *
// NSMutableDictionary* options = [notification.userInfo mutableCopy]; * @return [ Void ]
// */
// [options addEntriesFromDictionary:newOptions]; - (void) updateNotification:(UNNotificationRequest*)notification
// [options setObject:[NSDate date] forKey:@"updatedAt"]; withOptions:(NSDictionary*)newOptions
// {
//// notification = [[UILocalNotification alloc] NSMutableDictionary* options = [notification.content.userInfo mutableCopy];
//// initWithOptions:options];
//// [options addEntriesFromDictionary:newOptions];
//// [self scheduleLocalNotification:notification]; [options setObject:[NSDate date] forKey:@"updatedAt"];
//}
APPNotificationContent*
newNotification = [[APPNotificationContent alloc] initWithOptions:options];
[self scheduleNotification:newNotification];
}
#pragma mark - #pragma mark -
#pragma mark UNUserNotificationCenterDelegate #pragma mark UNUserNotificationCenterDelegate
...@@ -517,7 +503,10 @@ ...@@ -517,7 +503,10 @@
willPresentNotification:(UNNotification *)notification willPresentNotification:(UNNotification *)notification
withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler
{ {
[self fireEvent:@"trigger" notification:notification.request]; if (![notification.request wasUpdated]) {
[self fireEvent:@"trigger" notification:notification.request];
}
completionHandler(UNNotificationPresentationOptionBadge|UNNotificationPresentationOptionSound|UNNotificationPresentationOptionAlert); completionHandler(UNNotificationPresentationOptionBadge|UNNotificationPresentationOptionSound|UNNotificationPresentationOptionAlert);
} }
......
...@@ -27,6 +27,8 @@ ...@@ -27,6 +27,8 @@
// The options provided by the plug-in // The options provided by the plug-in
- (APPNotificationOptions*) options; - (APPNotificationOptions*) options;
// If the notification was updated
- (BOOL) wasUpdated;
// Encode the user info dict to JSON // Encode the user info dict to JSON
- (NSString*) encodeToJSON; - (NSString*) encodeToJSON;
......
...@@ -65,6 +65,16 @@ static char optionsKey; ...@@ -65,6 +65,16 @@ static char optionsKey;
} }
/** /**
* If the notification was updated.
*
* @return [ BOOL ]
*/
- (BOOL) wasUpdated
{
return [self.content userInfo][@"updatedAt"] != NULL;
}
/**
* Encode the user info dict to JSON. * Encode the user info dict to JSON.
*/ */
- (NSString*) encodeToJSON - (NSString*) encodeToJSON
......
...@@ -83,41 +83,38 @@ exports.schedule = function (msgs, callback, scope, args) { ...@@ -83,41 +83,38 @@ exports.schedule = function (msgs, callback, scope, args) {
} }
}; };
// /** /**
// * Update existing notifications specified by IDs in options. * Schedule notifications.
// * *
// * @param {Object} notifications * @param [ Array ] notifications The notifications to schedule.
// * The notification properties to update * @param [ Function ] callback The function to be exec as the callback.
// * @param {Function} callback * @param [ Object ] scope The callback function's scope.
// * A function to be called after the notification has been updated * @param [ Object ] args Optional flags how to schedule.
// * @param {Object?} scope *
// * The scope for the callback function * @return [ Void ]
// * @param {Object?} args */
// * skipPermission:true schedules the notifications immediatly without exports.update = function (msgs, callback, scope, args) {
// * registering or checking for permission var fn = function(granted) {
// */
// exports.update = function (msgs, callback, scope, args) { if (!granted) return;
// var fn = function(granted) {
var notifications = Array.isArray(msgs) ? msgs : [msgs];
// if (!granted) return;
for (var i = 0; i < notifications.length; i++) {
// var notifications = Array.isArray(msgs) ? msgs : [msgs]; var notification = notifications[i];
// for (var i = 0; i < notifications.length; i++) { this.convertProperties(notification);
// var notification = notifications[i]; }
// this.convertProperties(notification); this.exec('update', notifications, callback, scope);
// } };
// this.exec('update', notifications, callback, scope); if (args && args.skipPermission) {
// }; fn.call(this, true);
} else {
// if (args && args.skipPermission) { this.requestPermission(fn, this);
// fn.call(this, true); }
// } else { };
// this.registerPermission(fn, this);
// }
// };
/** /**
* Clear the specified notifications by id. * Clear the specified notifications by id.
......
...@@ -57,22 +57,19 @@ exports.schedule = function (notifications, callback, scope, args) { ...@@ -57,22 +57,19 @@ exports.schedule = function (notifications, callback, scope, args) {
this.core.schedule(notifications, callback, scope, args); this.core.schedule(notifications, callback, scope, args);
}; };
// /** /**
// * Update existing notifications specified by IDs in options. * Update notifications.
// * *
// * @param {Object} notifications * @param [ Array ] notifications The notifications to schedule.
// * The notification properties to update * @param [ Function ] callback The function to be exec as the callback.
// * @param {Function} callback * @param [ Object ] scope The callback function's scope.
// * A function to be called after the notification has been updated * @param [ Object ] args Optional flags how to schedule.
// * @param {Object?} scope *
// * The scope for the callback function * @return [ Void ]
// * @param {Object?} args */
// * skipPermission:true schedules the notifications immediatly without exports.update = function (notifications, callback, scope, args) {
// * registering or checking for permission this.core.update(notifications, callback, scope, args);
// */ };
// exports.update = function (notifications, callback, scope, args) {
// this.core.update(notifications, callback, scope, args);
// };
/** /**
* Clear the specified notifications by id. * Clear the specified notifications by id.
......
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