|
|
@@ -104,60 +104,36 @@
|
|
|
}];
|
|
|
}
|
|
|
|
|
|
-///**
|
|
|
-// * Update a set of notifications.
|
|
|
-// *
|
|
|
-// * @param properties
|
|
|
-// * A dict of properties for each notification
|
|
|
-// */
|
|
|
-//- (void) update:(CDVInvokedUrlCommand*)command
|
|
|
-//{
|
|
|
-// NSArray* notifications = command.arguments;
|
|
|
-//
|
|
|
-// [self.commandDelegate runInBackground:^{
|
|
|
-// if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"10.0")) {
|
|
|
-// for (NSDictionary* options in notifications) {
|
|
|
-// NSNumber* id = [options objectForKey:@"id"];
|
|
|
-// UNNotificationRequest* notification;
|
|
|
-//
|
|
|
-// notification = [_center getNotificationWithId:id];
|
|
|
-//
|
|
|
-// if (!notification)
|
|
|
-// continue;
|
|
|
-//
|
|
|
-// // [self updateNotification:[notification copy]
|
|
|
-// // withOptions:options];
|
|
|
-// //
|
|
|
-// // [self fireEvent:@"update" notification:notification];
|
|
|
-// //
|
|
|
-// // if (notifications.count > 1) {
|
|
|
-// // [NSThread sleepForTimeInterval:0.01];
|
|
|
-// // }
|
|
|
-// }
|
|
|
-// } 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];
|
|
|
-// }];
|
|
|
-//}
|
|
|
+/**
|
|
|
+ * Update notifications.
|
|
|
+ *
|
|
|
+ * @param [Array<Hash>] properties A list of key-value properties.
|
|
|
+ *
|
|
|
+ * @return [ Void ]
|
|
|
+ */
|
|
|
+- (void) update:(CDVInvokedUrlCommand*)command
|
|
|
+{
|
|
|
+ NSArray* notifications = command.arguments;
|
|
|
+
|
|
|
+ [self.commandDelegate runInBackground:^{
|
|
|
+ for (NSDictionary* options in notifications) {
|
|
|
+ NSNumber* id = [options objectForKey:@"id"];
|
|
|
+ UNNotificationRequest* notification;
|
|
|
+
|
|
|
+ notification = [_center getNotificationWithId:id];
|
|
|
+
|
|
|
+ if (!notification)
|
|
|
+ continue;
|
|
|
+
|
|
|
+ [self updateNotification:[notification copy]
|
|
|
+ withOptions:options];
|
|
|
+
|
|
|
+ [self fireEvent:@"update" notification:notification];
|
|
|
+ }
|
|
|
+
|
|
|
+ [self execCallback:command];
|
|
|
+ }];
|
|
|
+}
|
|
|
|
|
|
/**
|
|
|
* Clear notifications by id.
|
|
|
@@ -476,36 +452,46 @@
|
|
|
|
|
|
/**
|
|
|
* Schedule the local notification.
|
|
|
+ *
|
|
|
+ * @param [ APPNotificationContent* ] notification The notification to schedule.
|
|
|
+ *
|
|
|
+ * @return [ Void ]
|
|
|
*/
|
|
|
- (void) scheduleNotification:(APPNotificationContent*)notification
|
|
|
{
|
|
|
__weak APPLocalNotification* weakSelf = self;
|
|
|
UNNotificationRequest* request = notification.request;
|
|
|
+ NSString* event = [notification.request wasUpdated] ? @"update" : @"add";
|
|
|
|
|
|
[_center addNotificationCategory:notification.category];
|
|
|
|
|
|
[_center addNotificationRequest:request withCompletionHandler:^(NSError* e) {
|
|
|
__strong APPLocalNotification* strongSelf = weakSelf;
|
|
|
- [strongSelf fireEvent:@"add" notification:request];
|
|
|
+ [strongSelf fireEvent:event notification:request];
|
|
|
}];
|
|
|
}
|
|
|
|
|
|
-///**
|
|
|
-// * Update the local notification.
|
|
|
-// */
|
|
|
-//- (void) updateNotification:(UILocalNotification*)notification
|
|
|
-// withOptions:(NSDictionary*)newOptions
|
|
|
-//{APPNotificationRequest*
|
|
|
-// NSMutableDictionary* options = [notification.userInfo mutableCopy];
|
|
|
-//
|
|
|
-// [options addEntriesFromDictionary:newOptions];
|
|
|
-// [options setObject:[NSDate date] forKey:@"updatedAt"];
|
|
|
-//
|
|
|
-//// notification = [[UILocalNotification alloc]
|
|
|
-//// initWithOptions:options];
|
|
|
-////
|
|
|
-//// [self scheduleLocalNotification:notification];
|
|
|
-//}
|
|
|
+/**
|
|
|
+ * Update the local notification.
|
|
|
+ *
|
|
|
+ * @param [ UNNotificationRequest* ] notification The notification to update.
|
|
|
+ * @param [ NSDictionary* ] options The options to update.
|
|
|
+ *
|
|
|
+ * @return [ Void ]
|
|
|
+ */
|
|
|
+- (void) updateNotification:(UNNotificationRequest*)notification
|
|
|
+ withOptions:(NSDictionary*)newOptions
|
|
|
+{
|
|
|
+ NSMutableDictionary* options = [notification.content.userInfo mutableCopy];
|
|
|
+
|
|
|
+ [options addEntriesFromDictionary:newOptions];
|
|
|
+ [options setObject:[NSDate date] forKey:@"updatedAt"];
|
|
|
+
|
|
|
+ APPNotificationContent*
|
|
|
+ newNotification = [[APPNotificationContent alloc] initWithOptions:options];
|
|
|
+
|
|
|
+ [self scheduleNotification:newNotification];
|
|
|
+}
|
|
|
|
|
|
#pragma mark -
|
|
|
#pragma mark UNUserNotificationCenterDelegate
|
|
|
@@ -517,7 +503,10 @@
|
|
|
willPresentNotification:(UNNotification *)notification
|
|
|
withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler
|
|
|
{
|
|
|
- [self fireEvent:@"trigger" notification:notification.request];
|
|
|
+ if (![notification.request wasUpdated]) {
|
|
|
+ [self fireEvent:@"trigger" notification:notification.request];
|
|
|
+ }
|
|
|
+
|
|
|
completionHandler(UNNotificationPresentationOptionBadge|UNNotificationPresentationOptionSound|UNNotificationPresentationOptionAlert);
|
|
|
}
|
|
|
|