Commit f2fb5e10 by Sebastián Katzer

Internal code changes

parent 3cb3b51e
...@@ -141,52 +141,34 @@ public class LocalNotification extends CordovaPlugin { ...@@ -141,52 +141,34 @@ public class LocalNotification extends CordovaPlugin {
actions(args, command); actions(args, command);
} else } else
if (action.equals("schedule")) { if (action.equals("schedule")) {
schedule(args); schedule(args, command);
check(command);
} else } else
if (action.equals("update")) { if (action.equals("update")) {
update(args); update(args, command);
check(command);
} else } else
if (action.equals("cancel")) { if (action.equals("cancel")) {
cancel(args); cancel(args, command);
command.success();
} else } else
if (action.equals("cancelAll")) { if (action.equals("cancelAll")) {
cancelAll(); cancelAll(command);
command.success();
} else } else
if (action.equals("clear")) { if (action.equals("clear")) {
clear(args); clear(args, command);
command.success();
} else } else
if (action.equals("clearAll")) { if (action.equals("clearAll")) {
clearAll(); clearAll(command);
command.success();
} else } else
if (action.equals("type")) { if (action.equals("type")) {
type(args.optInt(0), command); type(args, command);
} else } else
if (action.equals("ids")) { if (action.equals("ids")) {
ids(command); ids(args, command);
} else
if (action.equals("scheduledIds")) {
scheduledIds(command);
} else
if (action.equals("triggeredIds")) {
triggeredIds(command);
} else } else
if (action.equals("notification")) { if (action.equals("notification")) {
notification(args.optInt(0), command); notification(args, command);
} else } else
if (action.equals("notifications")) { if (action.equals("notifications")) {
notifications(args, command); notifications(args, command);
} else
if (action.equals("scheduledNotifications")) {
scheduledNotifications(command);
} else
if (action.equals("triggeredNotifications")) {
triggeredNotifications(command);
} }
} }
}); });
...@@ -248,35 +230,23 @@ public class LocalNotification extends CordovaPlugin { ...@@ -248,35 +230,23 @@ public class LocalNotification extends CordovaPlugin {
* JavaScript. * JavaScript.
*/ */
private void actions (JSONArray args, CallbackContext command) { private void actions (JSONArray args, CallbackContext command) {
int task = args.optInt(0); int task = args.optInt(0);
String id = args.optString(1);
ActionGroup group; JSONObject spec = args.optJSONObject(2);
JSONObject spec;
boolean found;
String id;
switch (task) { switch (task) {
case 1: case 0:
spec = args.optJSONObject(1); ActionGroup group = ActionGroup.parse(cordova.getActivity(), spec);
group = ActionGroup.parse(cordova.getActivity(), spec);
if (group != null) ActionGroup.register(group); if (group != null) ActionGroup.register(group);
command.success(); command.success();
break; break;
case -1: case 1:
id = args.optString(1);
ActionGroup.unregister(id); ActionGroup.unregister(id);
command.success(); command.success();
break; break;
case 0: case 2:
id = args.optString(1); boolean found = ActionGroup.isRegistered(id);
found = ActionGroup.isRegistered(id);
success(command, found); success(command, found);
break; break;
} }
} }
...@@ -284,107 +254,130 @@ public class LocalNotification extends CordovaPlugin { ...@@ -284,107 +254,130 @@ public class LocalNotification extends CordovaPlugin {
/** /**
* Schedule multiple local notifications. * Schedule multiple local notifications.
* *
* @param notifications The notifications to schedule. * @param toasts The notifications to schedule.
* @param command The callback context used when calling back into
* JavaScript.
*/ */
private void schedule (JSONArray notifications) { private void schedule (JSONArray toasts, CallbackContext command) {
Manager mgr = getNotMgr(); Manager mgr = getNotMgr();
for (int i = 0; i < notifications.length(); i++) { for (int i = 0; i < toasts.length(); i++) {
JSONObject dict = notifications.optJSONObject(i); JSONObject dict = toasts.optJSONObject(i);
Options options = new Options(dict); Options options = new Options(dict);
Request request = new Request(options); Request request = new Request(options);
Notification toast = mgr.schedule(request, TriggerReceiver.class);
Notification notification =
mgr.schedule(request, TriggerReceiver.class);
if (notification != null) { if (toast != null) {
fireEvent("add", notification); fireEvent("add", toast);
} }
} }
check(command);
} }
/** /**
* Update multiple local notifications. * Update multiple local notifications.
* *
* @param updates Notification properties including their IDs * @param updates Notification properties including their IDs.
* @param command The callback context used when calling back into
* JavaScript.
*/ */
private void update (JSONArray updates) { private void update (JSONArray updates, CallbackContext command) {
for (int i = 0; i < updates.length(); i++) { Manager mgr = getNotMgr();
JSONObject update = updates.optJSONObject(i);
int id = update.optInt("id", 0);
Notification notification = for (int i = 0; i < updates.length(); i++) {
getNotMgr().update(id, update, TriggerReceiver.class); JSONObject update = updates.optJSONObject(i);
int id = update.optInt("id", 0);
Notification toast = mgr.update(id, update, TriggerReceiver.class);
if (notification == null) if (toast == null)
continue; continue;
fireEvent("update", notification); fireEvent("update", toast);
} }
check(command);
} }
/** /**
* Cancel multiple local notifications. * Cancel multiple local notifications.
* *
* @param ids Set of local notification IDs * @param ids Set of local notification IDs.
* @param command The callback context used when calling back into
* JavaScript.
*/ */
private void cancel (JSONArray ids) { private void cancel (JSONArray ids, CallbackContext command) {
for (int i = 0; i < ids.length(); i++) { Manager mgr = getNotMgr();
int id = ids.optInt(i, 0);
Notification notification = for (int i = 0; i < ids.length(); i++) {
getNotMgr().cancel(id); int id = ids.optInt(i, 0);
Notification toast = mgr.cancel(id);
if (notification == null) if (toast == null)
continue; continue;
fireEvent("cancel", notification); fireEvent("cancel", toast);
} }
command.success();
} }
/** /**
* Cancel all scheduled notifications. * Cancel all scheduled notifications.
*
* @param command The callback context used when calling back into
* JavaScript.
*/ */
private void cancelAll() { private void cancelAll(CallbackContext command) {
getNotMgr().cancelAll(); getNotMgr().cancelAll();
fireEvent("cancelall"); fireEvent("cancelall");
command.success();
} }
/** /**
* Clear multiple local notifications without canceling them. * Clear multiple local notifications without canceling them.
* *
* @param ids Set of local notification IDs * @param ids Set of local notification IDs.
* @param command The callback context used when calling back into
* JavaScript.
*/ */
private void clear(JSONArray ids){ private void clear(JSONArray ids, CallbackContext command) {
for (int i = 0; i < ids.length(); i++) { Manager mgr = getNotMgr();
int id = ids.optInt(i, 0);
Notification notification = for (int i = 0; i < ids.length(); i++) {
getNotMgr().clear(id); int id = ids.optInt(i, 0);
Notification toast = mgr.clear(id);
if (notification == null) if (toast == null)
continue; continue;
fireEvent("clear", notification); fireEvent("clear", toast);
} }
command.success();
} }
/** /**
* Clear all triggered notifications without canceling them. * Clear all triggered notifications without canceling them.
*
* @param command The callback context used when calling back into
* JavaScript.
*/ */
private void clearAll() { private void clearAll(CallbackContext command) {
getNotMgr().clearAll(); getNotMgr().clearAll();
fireEvent("clearall"); fireEvent("clearall");
command.success();
} }
/** /**
* Get the type of the notification (unknown, scheduled, triggered). * Get the type of the notification (unknown, scheduled, triggered).
* *
* @param id The ID of the notification to check. * @param args The exec() arguments in JSON form.
* @param command The callback context used when calling back into * @param command The callback context used when calling back into
* JavaScript. * JavaScript.
*/ */
private void type (int id, CallbackContext command) { private void type (JSONArray args, CallbackContext command) {
int id = args.optInt(0);
Notification toast = getNotMgr().get(id); Notification toast = getNotMgr().get(id);
if (toast == null) { if (toast == null) {
...@@ -408,48 +401,46 @@ public class LocalNotification extends CordovaPlugin { ...@@ -408,48 +401,46 @@ public class LocalNotification extends CordovaPlugin {
/** /**
* Set of IDs from all existent notifications. * Set of IDs from all existent notifications.
* *
* @param args The exec() arguments in JSON form.
* @param command The callback context used when calling back into * @param command The callback context used when calling back into
* JavaScript. * JavaScript.
*/ */
private void ids (CallbackContext command) { private void ids (JSONArray args, CallbackContext command) {
List<Integer> ids = getNotMgr().getIds(); int type = args.optInt(0);
command.success(new JSONArray(ids)); Manager mgr = getNotMgr();
} List<Integer> ids;
/** switch (type) {
* Set of IDs from all scheduled notifications. case 0:
* ids = mgr.getIds();
* @param command The callback context used when calling back into break;
* JavaScript. case 1:
*/ ids = mgr.getIdsByType(SCHEDULED);
private void scheduledIds (CallbackContext command) { break;
List<Integer> ids = getNotMgr().getIdsByType(SCHEDULED); case 2:
command.success(new JSONArray(ids)); ids = mgr.getIdsByType(TRIGGERED);
} break;
default:
ids = new ArrayList<Integer>(0);
break;
}
/**
* Set of IDs from all triggered notifications.
*
* @param command The callback context used when calling back into
* JavaScript.
*/
private void triggeredIds (CallbackContext command) {
List<Integer> ids = getNotMgr().getIdsByType(TRIGGERED);
command.success(new JSONArray(ids)); command.success(new JSONArray(ids));
} }
/** /**
* Options from local notification. * Options from local notification.
* *
* @param id The ID of the notification. * @param args The exec() arguments in JSON form.
* @param command The callback context used when calling back into * @param command The callback context used when calling back into
* JavaScript. * JavaScript.
*/ */
private void notification (int id, CallbackContext command) { private void notification (JSONArray args, CallbackContext command) {
Options options = getNotMgr().getOptions(id); int id = args.optInt(0);
Options opts = getNotMgr().getOptions(id);
if (options != null) { if (opts != null) {
command.success(options.getDict()); command.success(opts.getDict());
} else { } else {
command.success(); command.success();
} }
...@@ -458,48 +449,41 @@ public class LocalNotification extends CordovaPlugin { ...@@ -458,48 +449,41 @@ public class LocalNotification extends CordovaPlugin {
/** /**
* Set of options from local notification. * Set of options from local notification.
* *
* @param ids Set of local notification IDs. * @param args The exec() arguments in JSON form.
* @param command The callback context used when calling back into * @param command The callback context used when calling back into
* JavaScript. * JavaScript.
*/ */
private void notifications (JSONArray ids, CallbackContext command) { private void notifications (JSONArray args, CallbackContext command) {
int type = args.optInt(0);
JSONArray ids = args.optJSONArray(1);
Manager mgr = getNotMgr();
List<JSONObject> options; List<JSONObject> options;
if (ids.length() == 0) { switch (type) {
options = getNotMgr().getOptions(); case 0:
} else { options = mgr.getOptions();
options = getNotMgr().getOptionsById(toList(ids)); break;
case 1:
options = mgr.getOptionsByType(SCHEDULED);
break;
case 2:
options = mgr.getOptionsByType(TRIGGERED);
break;
case 3:
options = mgr.getOptionsById(toList(ids));
break;
default:
options = new ArrayList<JSONObject>(0);
break;
} }
command.success(new JSONArray(options)); command.success(new JSONArray(options));
} }
/** /**
* Set of options from scheduled notifications.
*
* @param command The callback context used when calling back into
* JavaScript.
*/
private void scheduledNotifications (CallbackContext command) {
List<JSONObject> options = getNotMgr().getOptionsByType(SCHEDULED);
command.success(new JSONArray(options));
}
/**
* Set of options from triggered notifications.
*
* @param command The callback context used when calling back into
* JavaScript.
*/
private void triggeredNotifications (CallbackContext command) {
List<JSONObject> options = getNotMgr().getOptionsByType(TRIGGERED);
command.success(new JSONArray(options));
}
/**
* Call all pending callbacks after the deviceready event has been fired. * Call all pending callbacks after the deviceready event has been fired.
*/ */
private static synchronized void deviceready () { private static synchronized void deviceready() {
deviceready = true; deviceready = true;
for (String js : eventQueue) { for (String js : eventQueue) {
......
...@@ -25,50 +25,28 @@ ...@@ -25,50 +25,28 @@
@interface APPLocalNotification : CDVPlugin <UNUserNotificationCenterDelegate> @interface APPLocalNotification : CDVPlugin <UNUserNotificationCenterDelegate>
// Set launchDetails object
- (void) launch:(CDVInvokedUrlCommand*)command; - (void) launch:(CDVInvokedUrlCommand*)command;
// Execute all queued events
- (void) ready:(CDVInvokedUrlCommand*)command; - (void) ready:(CDVInvokedUrlCommand*)command;
// Check permission to show notifications - (void) actions:(CDVInvokedUrlCommand*)command;
- (void) check:(CDVInvokedUrlCommand*)command; - (void) check:(CDVInvokedUrlCommand*)command;
// Request permission to show notifications
- (void) request:(CDVInvokedUrlCommand*)command; - (void) request:(CDVInvokedUrlCommand*)command;
// Register/update an action group
- (void) actions:(CDVInvokedUrlCommand*)command;
// Schedule notifications
- (void) schedule:(CDVInvokedUrlCommand*)command; - (void) schedule:(CDVInvokedUrlCommand*)command;
// Update set of notifications
- (void) update:(CDVInvokedUrlCommand*)command; - (void) update:(CDVInvokedUrlCommand*)command;
// Clear notifications by id
- (void) clear:(CDVInvokedUrlCommand*)command; - (void) clear:(CDVInvokedUrlCommand*)command;
// Clear all notifications
- (void) clearAll:(CDVInvokedUrlCommand*)command; - (void) clearAll:(CDVInvokedUrlCommand*)command;
// Cancel notifications by id
- (void) cancel:(CDVInvokedUrlCommand*)command; - (void) cancel:(CDVInvokedUrlCommand*)command;
// Cancel all notifications
- (void) cancelAll:(CDVInvokedUrlCommand*)command; - (void) cancelAll:(CDVInvokedUrlCommand*)command;
// Notification type
- (void) type:(CDVInvokedUrlCommand*)command; - (void) type:(CDVInvokedUrlCommand*)command;
// List of all notification IDs
- (void) ids:(CDVInvokedUrlCommand*)command; - (void) ids:(CDVInvokedUrlCommand*)command;
// List of all scheduled notification IDs
- (void) scheduledIds:(CDVInvokedUrlCommand*)command;
// List of all triggered notification IDs
- (void) triggeredIds:(CDVInvokedUrlCommand*)command;
// Notification by id
- (void) notification:(CDVInvokedUrlCommand*)command; - (void) notification:(CDVInvokedUrlCommand*)command;
// List of notifications by id
- (void) notifications:(CDVInvokedUrlCommand*)command; - (void) notifications:(CDVInvokedUrlCommand*)command;
// List of scheduled notifications by id
- (void) scheduledNotifications:(CDVInvokedUrlCommand*)command;
// List of triggered notifications by id
- (void) triggeredNotifications:(CDVInvokedUrlCommand*)command;
@end @end
...@@ -258,52 +258,34 @@ UNNotificationPresentationOptions const OptionAlert = UNNotificationPresentation ...@@ -258,52 +258,34 @@ UNNotificationPresentationOptions const OptionAlert = UNNotificationPresentation
} }
/** /**
* List of all notification IDs. * List of notification IDs by type.
* *
* @return [ Void ] * @return [ Void ]
*/ */
- (void) ids:(CDVInvokedUrlCommand*)command - (void) ids:(CDVInvokedUrlCommand*)command
{ {
[self ids:command byType:NotifcationTypeAll];
}
/**
* List of all scheduled notification IDs.
*
* @return [ Void ]
*/
- (void) scheduledIds:(CDVInvokedUrlCommand*)command
{
[self ids:command byType:NotifcationTypeScheduled];
}
/**
* List of all triggered notification IDs.
*
* @return [ Void ]
*/
- (void) triggeredIds:(CDVInvokedUrlCommand*)command
{
[self ids:command byType:NotifcationTypeTriggered];
}
/**
* List of ids for given local notifications.
*
* @param [ APPNotificationType ] type The type of notifications to look for.
*
* @return [ Void ]
*/
- (void) ids:(CDVInvokedUrlCommand*)command
byType:(APPNotificationType)type;
{
[self.commandDelegate runInBackground:^{ [self.commandDelegate runInBackground:^{
int code = [command.arguments[0] intValue];
APPNotificationType type = NotifcationTypeUnknown;
switch (code) {
case 0:
type = NotifcationTypeAll;
break;
case 1:
type = NotifcationTypeScheduled;
break;
case 2:
type = NotifcationTypeTriggered;
break;
}
NSArray* ids = [_center getNotificationIdsByType:type]; NSArray* ids = [_center getNotificationIdsByType:type];
CDVPluginResult* result; CDVPluginResult* result;
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK
messageAsArray:ids]; messageAsArray:ids];
[self.commandDelegate sendPluginResult:result [self.commandDelegate sendPluginResult:result
callbackId:command.callbackId]; callbackId:command.callbackId];
}]; }];
...@@ -342,58 +324,36 @@ UNNotificationPresentationOptions const OptionAlert = UNNotificationPresentation ...@@ -342,58 +324,36 @@ UNNotificationPresentationOptions const OptionAlert = UNNotificationPresentation
*/ */
- (void) notifications:(CDVInvokedUrlCommand*)command - (void) notifications:(CDVInvokedUrlCommand*)command
{ {
[self notifications:command byType:NotifcationTypeAll];
}
/**
* List of scheduled notifications by id.
*
* @param [ Array<Number> ] ids The ids of the notifications to return.
*
* @return [ Void ]
*/
- (void) scheduledNotifications:(CDVInvokedUrlCommand*)command
{
[self notifications:command byType:NotifcationTypeScheduled];
}
/**
* List of triggered notifications by id.
*
* @param [ Array<Number> ] ids The ids of the notifications to return.
*
* @return [ Void ]
*/
- (void) triggeredNotifications:(CDVInvokedUrlCommand *)command
{
[self notifications:command byType:NotifcationTypeTriggered];
}
/**
* List of notifications by type or id.
*
* @param [ APPNotificationType ] type The type of notifications to look for.
*
* @return [ Void ]
*/
- (void) notifications:(CDVInvokedUrlCommand*)command
byType:(APPNotificationType)type;
{
[self.commandDelegate runInBackground:^{ [self.commandDelegate runInBackground:^{
NSArray* ids = command.arguments; int code = [command.arguments[0] intValue];
NSArray* notifications; APPNotificationType type = NotifcationTypeUnknown;
NSArray* toasts;
if (ids.count > 0) { NSArray* ids;
notifications = [_center getNotificationOptionsById:ids];
switch (code) {
case 0:
type = NotifcationTypeAll;
break;
case 1:
type = NotifcationTypeScheduled;
break;
case 2:
type = NotifcationTypeTriggered;
break;
case 3:
ids = command.arguments[1];
toasts = [_center getNotificationOptionsById:ids];
break;
} }
else {
notifications = [_center getNotificationOptionsByType:type]; if (toasts == nil) {
toasts = [_center getNotificationOptionsByType:type];
} }
CDVPluginResult* result; CDVPluginResult* result;
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK
messageAsArray:notifications]; messageAsArray:toasts];
[self.commandDelegate sendPluginResult:result [self.commandDelegate sendPluginResult:result
callbackId:command.callbackId]; callbackId:command.callbackId];
}]; }];
...@@ -438,35 +398,27 @@ UNNotificationPresentationOptions const OptionAlert = UNNotificationPresentation ...@@ -438,35 +398,27 @@ UNNotificationPresentationOptions const OptionAlert = UNNotificationPresentation
- (void) actions:(CDVInvokedUrlCommand *)command - (void) actions:(CDVInvokedUrlCommand *)command
{ {
[self.commandDelegate runInBackground:^{ [self.commandDelegate runInBackground:^{
int task = [command.arguments[0] intValue]; int code = [command.arguments[0] intValue];
NSString* identifier = [command argumentAtIndex:1];
NSDictionary* options = [command argumentAtIndex:2];
APPNotificationContent* notification; APPNotificationContent* notification;
NSDictionary* options;
NSString* identifier;
BOOL found; BOOL found;
switch (task) { switch (code) {
case 1: case 0:
options = command.arguments[1];
notification = [[APPNotificationContent alloc] notification = [[APPNotificationContent alloc]
initWithOptions:options]; initWithOptions:options];
[_center addActionGroup:notification.category]; [_center addActionGroup:notification.category];
[self execCallback:command]; [self execCallback:command];
break; break;
case -1: case 1:
identifier = command.arguments[1];
[_center removeActionGroup:identifier]; [_center removeActionGroup:identifier];
[self execCallback:command]; [self execCallback:command];
break; break;
case 0: case 2:
identifier = command.arguments[1];
found = [_center hasActionGroup:identifier]; found = [_center hasActionGroup:identifier];
[self execCallback:command arg:found]; [self execCallback:command arg:found];
break; break;
} }
}]; }];
...@@ -667,7 +619,7 @@ UNNotificationPresentationOptions const OptionAlert = UNNotificationPresentation ...@@ -667,7 +619,7 @@ UNNotificationPresentationOptions const OptionAlert = UNNotificationPresentation
CDVPluginResult *result = [CDVPluginResult CDVPluginResult *result = [CDVPluginResult
resultWithStatus:CDVCommandStatus_OK resultWithStatus:CDVCommandStatus_OK
messageAsBool:arg]; messageAsBool:arg];
[self.commandDelegate sendPluginResult:result [self.commandDelegate sendPluginResult:result
callbackId:command.callbackId]; callbackId:command.callbackId];
} }
......
...@@ -106,7 +106,7 @@ NSString * const kAPPGeneralCategory = @"GENERAL"; ...@@ -106,7 +106,7 @@ NSString * const kAPPGeneralCategory = @"GENERAL";
* *
* @param [ NSString* ] identifier The category id to check for. * @param [ NSString* ] identifier The category id to check for.
* *
* @return [ Void ] * @return [ BOOL ]
*/ */
- (BOOL) hasActionGroup:(NSString*)identifier - (BOOL) hasActionGroup:(NSString*)identifier
{ {
...@@ -134,6 +134,8 @@ NSString * const kAPPGeneralCategory = @"GENERAL"; ...@@ -134,6 +134,8 @@ NSString * const kAPPGeneralCategory = @"GENERAL";
/** /**
* List of all delivered or still pending notifications. * List of all delivered or still pending notifications.
*
* @return [ NSArray<UNNotificationRequest*>* ]
*/ */
- (NSArray*) getNotifications - (NSArray*) getNotifications
{ {
...@@ -147,6 +149,8 @@ NSString * const kAPPGeneralCategory = @"GENERAL"; ...@@ -147,6 +149,8 @@ NSString * const kAPPGeneralCategory = @"GENERAL";
/** /**
* List of all triggered notifications. * List of all triggered notifications.
*
* @return [ NSArray<UNNotificationRequest*>* ]
*/ */
- (NSArray*) getDeliveredNotifications - (NSArray*) getDeliveredNotifications
{ {
...@@ -168,6 +172,8 @@ NSString * const kAPPGeneralCategory = @"GENERAL"; ...@@ -168,6 +172,8 @@ NSString * const kAPPGeneralCategory = @"GENERAL";
/** /**
* List of all pending notifications. * List of all pending notifications.
*
* @return [ NSArray<UNNotificationRequest*>* ]
*/ */
- (NSArray*) getPendingNotifications - (NSArray*) getPendingNotifications
{ {
...@@ -187,8 +193,9 @@ NSString * const kAPPGeneralCategory = @"GENERAL"; ...@@ -187,8 +193,9 @@ NSString * const kAPPGeneralCategory = @"GENERAL";
/** /**
* List of all notifications from given type. * List of all notifications from given type.
* *
* @param type * @param [ APPNotificationType ] type Notification life cycle type.
* Notification life cycle type *
* @return [ NSArray<UNNotificationRequest>* ]
*/ */
- (NSArray*) getNotificationsByType:(APPNotificationType)type - (NSArray*) getNotificationsByType:(APPNotificationType)type
{ {
...@@ -206,6 +213,8 @@ NSString * const kAPPGeneralCategory = @"GENERAL"; ...@@ -206,6 +213,8 @@ NSString * const kAPPGeneralCategory = @"GENERAL";
/** /**
* List of all local notifications IDs. * List of all local notifications IDs.
*
* @return [ NSArray<int>* ]
*/ */
- (NSArray*) getNotificationIds - (NSArray*) getNotificationIds
{ {
...@@ -223,8 +232,9 @@ NSString * const kAPPGeneralCategory = @"GENERAL"; ...@@ -223,8 +232,9 @@ NSString * const kAPPGeneralCategory = @"GENERAL";
/** /**
* List of all notifications IDs from given type. * List of all notifications IDs from given type.
* *
* @param type * @param [ APPNotificationType ] type Notification life cycle type.
* Notification life cycle type *
* @return [ NSArray<int>* ]
*/ */
- (NSArray*) getNotificationIdsByType:(APPNotificationType)type - (NSArray*) getNotificationIdsByType:(APPNotificationType)type
{ {
...@@ -242,8 +252,9 @@ NSString * const kAPPGeneralCategory = @"GENERAL"; ...@@ -242,8 +252,9 @@ NSString * const kAPPGeneralCategory = @"GENERAL";
/** /**
* Find notification by ID. * Find notification by ID.
* *
* @param id * @param id Notification ID
* Notification ID *
* @return [ UNNotificationRequest* ]
*/ */
- (UNNotificationRequest*) getNotificationWithId:(NSNumber*)id - (UNNotificationRequest*) getNotificationWithId:(NSNumber*)id
{ {
...@@ -262,7 +273,11 @@ NSString * const kAPPGeneralCategory = @"GENERAL"; ...@@ -262,7 +273,11 @@ NSString * const kAPPGeneralCategory = @"GENERAL";
} }
/** /**
* Find notification type by ID * Find notification type by ID.
*
* @param [ NSNumber* ] id The ID of the notification.
*
* @return [ APPNotificationType ]
*/ */
- (APPNotificationType) getTypeOfNotificationWithId:(NSNumber*)id - (APPNotificationType) getTypeOfNotificationWithId:(NSNumber*)id
{ {
...@@ -281,6 +296,8 @@ NSString * const kAPPGeneralCategory = @"GENERAL"; ...@@ -281,6 +296,8 @@ NSString * const kAPPGeneralCategory = @"GENERAL";
/** /**
* List of properties from all notifications. * List of properties from all notifications.
*
* @return [ NSArray<APPNotificationOptions*>* ]
*/ */
- (NSArray*) getNotificationOptions - (NSArray*) getNotificationOptions
{ {
...@@ -290,8 +307,9 @@ NSString * const kAPPGeneralCategory = @"GENERAL"; ...@@ -290,8 +307,9 @@ NSString * const kAPPGeneralCategory = @"GENERAL";
/** /**
* List of properties from all notifications of given type. * List of properties from all notifications of given type.
* *
* @param type * @param [ APPNotificationType ] type Notification life cycle type.
* Notification life cycle type *
* @return [ NSArray<APPNotificationOptions*>* ]
*/ */
- (NSArray*) getNotificationOptionsByType:(APPNotificationType)type - (NSArray*) getNotificationOptionsByType:(APPNotificationType)type
{ {
...@@ -309,8 +327,9 @@ NSString * const kAPPGeneralCategory = @"GENERAL"; ...@@ -309,8 +327,9 @@ NSString * const kAPPGeneralCategory = @"GENERAL";
/** /**
* List of properties from given local notifications. * List of properties from given local notifications.
* *
* @param ids * @param [ NSArray<int> ] ids The ids of the notifications to find.
* Notification IDs *
* @return [ NSArray<APPNotificationOptions*>* ]
*/ */
- (NSArray*) getNotificationOptionsById:(NSArray*)ids - (NSArray*) getNotificationOptionsById:(NSArray*)ids
{ {
...@@ -329,6 +348,8 @@ NSString * const kAPPGeneralCategory = @"GENERAL"; ...@@ -329,6 +348,8 @@ NSString * const kAPPGeneralCategory = @"GENERAL";
/* /*
* Clear all notfications. * Clear all notfications.
*
* @return [ Void ]
*/ */
- (void) clearNotifications - (void) clearNotifications
{ {
...@@ -338,19 +359,19 @@ NSString * const kAPPGeneralCategory = @"GENERAL"; ...@@ -338,19 +359,19 @@ NSString * const kAPPGeneralCategory = @"GENERAL";
/* /*
* Clear Specified notfication. * Clear Specified notfication.
* *
* @param notification * @param [ UNNotificationRequest* ] notification The notification object.
* The notification object *
* @return [ Void ]
*/ */
- (void) clearNotification:(UNNotificationRequest*)notification - (void) clearNotification:(UNNotificationRequest*)toast
{ {
NSArray* ids = [[NSArray alloc] [self removeDeliveredNotificationsWithIdentifiers:@[toast.identifier]];
initWithObjects:notification.identifier, nil];
[self removeDeliveredNotificationsWithIdentifiers:ids];
} }
/* /*
* Cancel all notfications. * Cancel all notfications.
*
* @return [ Void ]
*/ */
- (void) cancelNotifications - (void) cancelNotifications
{ {
...@@ -361,14 +382,14 @@ NSString * const kAPPGeneralCategory = @"GENERAL"; ...@@ -361,14 +382,14 @@ NSString * const kAPPGeneralCategory = @"GENERAL";
/* /*
* Cancel specified notfication. * Cancel specified notfication.
* *
* @param notification * @param [ UNNotificationRequest* ] notification The notification object.
* The notification object *
* @return [ Void ]
*/ */
- (void) cancelNotification:(UNNotificationRequest*)notification - (void) cancelNotification:(UNNotificationRequest*)toast
{ {
NSArray* ids = [[NSArray alloc] NSArray* ids = @[toast.identifier];
initWithObjects:notification.identifier, nil];
[self removeDeliveredNotificationsWithIdentifiers:ids]; [self removeDeliveredNotificationsWithIdentifiers:ids];
[self removePendingNotificationRequestsWithIdentifiers:ids]; [self removePendingNotificationRequestsWithIdentifiers:ids];
} }
......
...@@ -292,7 +292,7 @@ exports.getType = function (id, callback, scope) { ...@@ -292,7 +292,7 @@ exports.getType = function (id, callback, scope) {
* @return [ Void ] * @return [ Void ]
*/ */
exports.getIds = function (callback, scope) { exports.getIds = function (callback, scope) {
this._exec('ids', null, callback, scope); this._exec('ids', 0, callback, scope);
}; };
/** /**
...@@ -304,7 +304,7 @@ exports.getIds = function (callback, scope) { ...@@ -304,7 +304,7 @@ exports.getIds = function (callback, scope) {
* @return [ Void ] * @return [ Void ]
*/ */
exports.getScheduledIds = function (callback, scope) { exports.getScheduledIds = function (callback, scope) {
this._exec('scheduledIds', null, callback, scope); this._exec('ids', 1, callback, scope);
}; };
/** /**
...@@ -316,7 +316,7 @@ exports.getScheduledIds = function (callback, scope) { ...@@ -316,7 +316,7 @@ exports.getScheduledIds = function (callback, scope) {
* @return [ Void ] * @return [ Void ]
*/ */
exports.getTriggeredIds = function (callback, scope) { exports.getTriggeredIds = function (callback, scope) {
this._exec('triggeredIds', null, callback, scope); this._exec('ids', 2, callback, scope);
}; };
/** /**
...@@ -347,7 +347,7 @@ exports.get = function () { ...@@ -347,7 +347,7 @@ exports.get = function () {
ids = this._convertIds(ids); ids = this._convertIds(ids);
this._exec('notifications', ids, callback, scope); this._exec('notifications', [3, ids], callback, scope);
}; };
/** /**
...@@ -359,7 +359,7 @@ exports.get = function () { ...@@ -359,7 +359,7 @@ exports.get = function () {
* @return [ Void ] * @return [ Void ]
*/ */
exports.getAll = function (callback, scope) { exports.getAll = function (callback, scope) {
this._exec('notifications', null, callback, scope); this._exec('notifications', 0, callback, scope);
}; };
/** /**
...@@ -369,7 +369,7 @@ exports.getAll = function (callback, scope) { ...@@ -369,7 +369,7 @@ exports.getAll = function (callback, scope) {
* @param [ Object ] scope The callback function's scope. * @param [ Object ] scope The callback function's scope.
*/ */
exports.getScheduled = function (callback, scope) { exports.getScheduled = function (callback, scope) {
this._exec('scheduledNotifications', null, callback, scope); this._exec('notifications', 1, callback, scope);
}; };
/** /**
...@@ -379,7 +379,7 @@ exports.getScheduled = function (callback, scope) { ...@@ -379,7 +379,7 @@ exports.getScheduled = function (callback, scope) {
* @param [ Object ] scope The callback function's scope. * @param [ Object ] scope The callback function's scope.
*/ */
exports.getTriggered = function (callback, scope) { exports.getTriggered = function (callback, scope) {
this._exec('triggeredNotifications', null, callback, scope); this._exec('notifications', 2, callback, scope);
}; };
/** /**
...@@ -394,7 +394,7 @@ exports.getTriggered = function (callback, scope) { ...@@ -394,7 +394,7 @@ exports.getTriggered = function (callback, scope) {
*/ */
exports.addActions = function (id, actions, callback, scope) { exports.addActions = function (id, actions, callback, scope) {
var config = { actionGroupId: id, actions: actions }; var config = { actionGroupId: id, actions: actions };
this._exec('actions', [1, config], callback, scope); this._exec('actions', [0, id, config], callback, scope);
}; };
/** /**
...@@ -407,7 +407,7 @@ exports.addActions = function (id, actions, callback, scope) { ...@@ -407,7 +407,7 @@ exports.addActions = function (id, actions, callback, scope) {
* @return [ Void ] * @return [ Void ]
*/ */
exports.removeActions = function (id, callback, scope) { exports.removeActions = function (id, callback, scope) {
this._exec('actions', [-1, id], callback, scope); this._exec('actions', [1, id], callback, scope);
}; };
/** /**
...@@ -420,7 +420,7 @@ exports.removeActions = function (id, callback, scope) { ...@@ -420,7 +420,7 @@ exports.removeActions = function (id, callback, scope) {
* @return [ Void ] * @return [ Void ]
*/ */
exports.hasActions = function (id, callback, scope) { exports.hasActions = function (id, callback, scope) {
this._exec('actions', [0, id], callback, scope); this._exec('actions', [2, id], callback, scope);
}; };
/** /**
......
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