Commit f2fb5e10 by Sebastián Katzer

Internal code changes

parent 3cb3b51e
...@@ -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