Commit f2fb5e10 by Sebastián Katzer

Internal code changes

parent 3cb3b51e
......@@ -25,50 +25,28 @@
@interface APPLocalNotification : CDVPlugin <UNUserNotificationCenterDelegate>
// Set launchDetails object
- (void) launch:(CDVInvokedUrlCommand*)command;
// Execute all queued events
- (void) ready:(CDVInvokedUrlCommand*)command;
// Check permission to show notifications
- (void) actions:(CDVInvokedUrlCommand*)command;
- (void) check:(CDVInvokedUrlCommand*)command;
// Request permission to show notifications
- (void) request:(CDVInvokedUrlCommand*)command;
// Register/update an action group
- (void) actions:(CDVInvokedUrlCommand*)command;
// Schedule notifications
- (void) schedule:(CDVInvokedUrlCommand*)command;
// Update set of notifications
- (void) update:(CDVInvokedUrlCommand*)command;
// Clear notifications by id
- (void) clear:(CDVInvokedUrlCommand*)command;
// Clear all notifications
- (void) clearAll:(CDVInvokedUrlCommand*)command;
// Cancel notifications by id
- (void) cancel:(CDVInvokedUrlCommand*)command;
// Cancel all notifications
- (void) cancelAll:(CDVInvokedUrlCommand*)command;
// Notification type
- (void) type:(CDVInvokedUrlCommand*)command;
// List of all notification IDs
- (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;
// List of notifications by id
- (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
......@@ -258,52 +258,34 @@ UNNotificationPresentationOptions const OptionAlert = UNNotificationPresentation
}
/**
* List of all notification IDs.
* List of notification IDs by type.
*
* @return [ Void ]
*/
- (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:^{
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];
CDVPluginResult* result;
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK
messageAsArray:ids];
[self.commandDelegate sendPluginResult:result
callbackId:command.callbackId];
}];
......@@ -342,58 +324,36 @@ UNNotificationPresentationOptions const OptionAlert = UNNotificationPresentation
*/
- (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:^{
NSArray* ids = command.arguments;
NSArray* notifications;
if (ids.count > 0) {
notifications = [_center getNotificationOptionsById:ids];
int code = [command.arguments[0] intValue];
APPNotificationType type = NotifcationTypeUnknown;
NSArray* toasts;
NSArray* 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;
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK
messageAsArray:notifications];
messageAsArray:toasts];
[self.commandDelegate sendPluginResult:result
callbackId:command.callbackId];
}];
......@@ -438,35 +398,27 @@ UNNotificationPresentationOptions const OptionAlert = UNNotificationPresentation
- (void) actions:(CDVInvokedUrlCommand *)command
{
[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;
NSDictionary* options;
NSString* identifier;
BOOL found;
switch (task) {
case 1:
options = command.arguments[1];
switch (code) {
case 0:
notification = [[APPNotificationContent alloc]
initWithOptions:options];
[_center addActionGroup:notification.category];
[self execCallback:command];
break;
case -1:
identifier = command.arguments[1];
case 1:
[_center removeActionGroup:identifier];
[self execCallback:command];
break;
case 0:
identifier = command.arguments[1];
case 2:
found = [_center hasActionGroup:identifier];
[self execCallback:command arg:found];
break;
}
}];
......@@ -667,7 +619,7 @@ UNNotificationPresentationOptions const OptionAlert = UNNotificationPresentation
CDVPluginResult *result = [CDVPluginResult
resultWithStatus:CDVCommandStatus_OK
messageAsBool:arg];
[self.commandDelegate sendPluginResult:result
callbackId:command.callbackId];
}
......
......@@ -106,7 +106,7 @@ NSString * const kAPPGeneralCategory = @"GENERAL";
*
* @param [ NSString* ] identifier The category id to check for.
*
* @return [ Void ]
* @return [ BOOL ]
*/
- (BOOL) hasActionGroup:(NSString*)identifier
{
......@@ -134,6 +134,8 @@ NSString * const kAPPGeneralCategory = @"GENERAL";
/**
* List of all delivered or still pending notifications.
*
* @return [ NSArray<UNNotificationRequest*>* ]
*/
- (NSArray*) getNotifications
{
......@@ -147,6 +149,8 @@ NSString * const kAPPGeneralCategory = @"GENERAL";
/**
* List of all triggered notifications.
*
* @return [ NSArray<UNNotificationRequest*>* ]
*/
- (NSArray*) getDeliveredNotifications
{
......@@ -168,6 +172,8 @@ NSString * const kAPPGeneralCategory = @"GENERAL";
/**
* List of all pending notifications.
*
* @return [ NSArray<UNNotificationRequest*>* ]
*/
- (NSArray*) getPendingNotifications
{
......@@ -187,8 +193,9 @@ NSString * const kAPPGeneralCategory = @"GENERAL";
/**
* List of all notifications from given type.
*
* @param type
* Notification life cycle type
* @param [ APPNotificationType ] type Notification life cycle type.
*
* @return [ NSArray<UNNotificationRequest>* ]
*/
- (NSArray*) getNotificationsByType:(APPNotificationType)type
{
......@@ -206,6 +213,8 @@ NSString * const kAPPGeneralCategory = @"GENERAL";
/**
* List of all local notifications IDs.
*
* @return [ NSArray<int>* ]
*/
- (NSArray*) getNotificationIds
{
......@@ -223,8 +232,9 @@ NSString * const kAPPGeneralCategory = @"GENERAL";
/**
* List of all notifications IDs from given type.
*
* @param type
* Notification life cycle type
* @param [ APPNotificationType ] type Notification life cycle type.
*
* @return [ NSArray<int>* ]
*/
- (NSArray*) getNotificationIdsByType:(APPNotificationType)type
{
......@@ -242,8 +252,9 @@ NSString * const kAPPGeneralCategory = @"GENERAL";
/**
* Find notification by ID.
*
* @param id
* Notification ID
* @param id Notification ID
*
* @return [ UNNotificationRequest* ]
*/
- (UNNotificationRequest*) getNotificationWithId:(NSNumber*)id
{
......@@ -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
{
......@@ -281,6 +296,8 @@ NSString * const kAPPGeneralCategory = @"GENERAL";
/**
* List of properties from all notifications.
*
* @return [ NSArray<APPNotificationOptions*>* ]
*/
- (NSArray*) getNotificationOptions
{
......@@ -290,8 +307,9 @@ NSString * const kAPPGeneralCategory = @"GENERAL";
/**
* List of properties from all notifications of given type.
*
* @param type
* Notification life cycle type
* @param [ APPNotificationType ] type Notification life cycle type.
*
* @return [ NSArray<APPNotificationOptions*>* ]
*/
- (NSArray*) getNotificationOptionsByType:(APPNotificationType)type
{
......@@ -309,8 +327,9 @@ NSString * const kAPPGeneralCategory = @"GENERAL";
/**
* List of properties from given local notifications.
*
* @param ids
* Notification IDs
* @param [ NSArray<int> ] ids The ids of the notifications to find.
*
* @return [ NSArray<APPNotificationOptions*>* ]
*/
- (NSArray*) getNotificationOptionsById:(NSArray*)ids
{
......@@ -329,6 +348,8 @@ NSString * const kAPPGeneralCategory = @"GENERAL";
/*
* Clear all notfications.
*
* @return [ Void ]
*/
- (void) clearNotifications
{
......@@ -338,19 +359,19 @@ NSString * const kAPPGeneralCategory = @"GENERAL";
/*
* Clear Specified notfication.
*
* @param notification
* The notification object
* @param [ UNNotificationRequest* ] notification The notification object.
*
* @return [ Void ]
*/
- (void) clearNotification:(UNNotificationRequest*)notification
- (void) clearNotification:(UNNotificationRequest*)toast
{
NSArray* ids = [[NSArray alloc]
initWithObjects:notification.identifier, nil];
[self removeDeliveredNotificationsWithIdentifiers:ids];
[self removeDeliveredNotificationsWithIdentifiers:@[toast.identifier]];
}
/*
* Cancel all notfications.
*
* @return [ Void ]
*/
- (void) cancelNotifications
{
......@@ -361,14 +382,14 @@ NSString * const kAPPGeneralCategory = @"GENERAL";
/*
* Cancel specified notfication.
*
* @param notification
* The notification object
* @param [ UNNotificationRequest* ] notification The notification object.
*
* @return [ Void ]
*/
- (void) cancelNotification:(UNNotificationRequest*)notification
- (void) cancelNotification:(UNNotificationRequest*)toast
{
NSArray* ids = [[NSArray alloc]
initWithObjects:notification.identifier, nil];
NSArray* ids = @[toast.identifier];
[self removeDeliveredNotificationsWithIdentifiers:ids];
[self removePendingNotificationRequestsWithIdentifiers:ids];
}
......
......@@ -292,7 +292,7 @@ exports.getType = function (id, callback, scope) {
* @return [ Void ]
*/
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) {
* @return [ Void ]
*/
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) {
* @return [ Void ]
*/
exports.getTriggeredIds = function (callback, scope) {
this._exec('triggeredIds', null, callback, scope);
this._exec('ids', 2, callback, scope);
};
/**
......@@ -347,7 +347,7 @@ exports.get = function () {
ids = this._convertIds(ids);
this._exec('notifications', ids, callback, scope);
this._exec('notifications', [3, ids], callback, scope);
};
/**
......@@ -359,7 +359,7 @@ exports.get = function () {
* @return [ Void ]
*/
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) {
* @param [ Object ] scope The callback function's 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) {
* @param [ Object ] scope The callback function's 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) {
*/
exports.addActions = function (id, actions, callback, scope) {
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) {
* @return [ Void ]
*/
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) {
* @return [ Void ]
*/
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