Commit 8418c152 by Sebastián Katzer

New interface methods `getScheduled` and `getTriggered` (iOS)

parent 40599e17
......@@ -36,10 +36,14 @@
- (void) isScheduled:(CDVInvokedUrlCommand*)command;
// Check if a notification with an ID was triggered
- (void) isTriggered:(CDVInvokedUrlCommand*)command;
// Retrieve a list of ids from all pending notifications
// List all ids from all pending notifications
- (void) getScheduledIds:(CDVInvokedUrlCommand*)command;
// Retrieve a list of ids from all triggered notifications
// List all ids from all triggered notifications
- (void) getTriggeredIds:(CDVInvokedUrlCommand*)command;
// List all properties for given scheduled notifications
- (void) getScheduled:(CDVInvokedUrlCommand*)command;
// List all properties for given triggered notifications
- (void) getTriggered:(CDVInvokedUrlCommand*)command;
// Inform if the app has the permission to show notifications
- (void) hasPermission:(CDVInvokedUrlCommand*)command;
// Register permission to show notifications
......
......@@ -117,7 +117,7 @@
}
/**
* Cancels all currently scheduled notifications.
* Cancel all currently scheduled notifications.
*/
- (void) cancelAll:(CDVInvokedUrlCommand*)command
{
......@@ -157,7 +157,35 @@
}
/**
* List of ids from all currently pending notifications.
* Check if a notification with an ID was triggered.
*
* @param id
* The ID of the notification
*/
- (void) isTriggered:(CDVInvokedUrlCommand*)command
{
[self.commandDelegate runInBackground:^{
NSString* id = [[command arguments]
objectAtIndex:0];
CDVPluginResult* result;
UILocalNotification* notification;
notification = [[UIApplication sharedApplication]
triggeredLocalNotificationWithId:id];
bool isTriggered = notification != NULL;
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK
messageAsBool:isTriggered];
[self.commandDelegate sendPluginResult:result
callbackId:command.callbackId];
}];
}
/**
* List all ids from all pending notifications.
*/
- (void) getScheduledIds:(CDVInvokedUrlCommand*)command
{
......@@ -177,27 +205,48 @@
}
/**
* Checks wether a notification with an ID was triggered.
*
* @param id
* The ID of the notification
* List all ids from all triggered notifications.
*/
- (void) isTriggered:(CDVInvokedUrlCommand*)command
- (void) getTriggeredIds:(CDVInvokedUrlCommand*)command
{
[self.commandDelegate runInBackground:^{
NSString* id = [[command arguments]
objectAtIndex:0];
CDVPluginResult* result;
UILocalNotification* notification;
NSArray* triggeredIds;
notification = [[UIApplication sharedApplication]
triggeredLocalNotificationWithId:id];
triggeredIds = [[UIApplication sharedApplication]
triggeredLocalNotificationIds];
bool isTriggered = notification != NULL;
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK
messageAsArray:triggeredIds];
[self.commandDelegate sendPluginResult:result
callbackId:command.callbackId];
}];
}
/**
* List all properties for given scheduled notifications.
*
* @param ids
* The IDs of the notifications
*/
- (void) getScheduled:(CDVInvokedUrlCommand*)command
{
[self.commandDelegate runInBackground:^{
NSArray* ids = command.arguments;
NSArray* notifications;
CDVPluginResult* result;
if (ids.count == 0) {
notifications = [[UIApplication sharedApplication]
scheduledLocalNotificationOptions];
} else {
notifications = [[UIApplication sharedApplication]
scheduledLocalNotificationOptions:ids];
}
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK
messageAsBool:isTriggered];
messageAsArray:notifications];
[self.commandDelegate sendPluginResult:result
callbackId:command.callbackId];
......@@ -205,19 +254,28 @@
}
/**
* Retrieves a list of ids from all currently triggered notifications.
* List all properties for given triggered notifications.
*
* @param ids
* The IDs of the notifications
*/
- (void) getTriggeredIds:(CDVInvokedUrlCommand*)command
- (void) getTriggered:(CDVInvokedUrlCommand *)command
{
[self.commandDelegate runInBackground:^{
NSArray* ids = command.arguments;
NSArray* notifications;
CDVPluginResult* result;
NSArray* triggeredIds;
triggeredIds = [[UIApplication sharedApplication]
triggeredLocalNotificationIds];
if (ids.count == 0) {
notifications = [[UIApplication sharedApplication]
triggeredLocalNotificationOptions];
} else {
notifications = [[UIApplication sharedApplication]
triggeredLocalNotificationOptions:ids];
}
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK
messageAsArray:triggeredIds];
messageAsArray:notifications];
[self.commandDelegate sendPluginResult:result
callbackId:command.callbackId];
......
......@@ -33,5 +33,13 @@
- (UILocalNotification*) scheduledLocalNotificationWithId:(NSString*)id;
// Get the triggered local notification by ID
- (UILocalNotification*) triggeredLocalNotificationWithId:(NSString*)id;
// List of properties from all scheduled notifications
- (NSArray*) scheduledLocalNotificationOptions;
// List of properties from given scheduled notifications
- (NSArray*) scheduledLocalNotificationOptions:(NSArray*)ids;
// List of properties from all triggered notifications
- (NSArray*) triggeredLocalNotificationOptions;
// List of properties from given triggered notifications
- (NSArray*) triggeredLocalNotificationOptions:(NSArray*)ids;
@end
......@@ -97,15 +97,15 @@
*/
- (NSArray*) triggeredLocalNotificationIds
{
NSArray* triggeredNotifications = self.triggeredLocalNotifications;
NSMutableArray* triggeredNotificationIds = [[NSMutableArray alloc] init];
NSArray* notifications = self.triggeredLocalNotifications;
NSMutableArray* ids = [[NSMutableArray alloc] init];
for (UILocalNotification* notification in triggeredNotifications)
for (UILocalNotification* notification in notifications)
{
[triggeredNotificationIds addObject:notification.options.id];
[ids addObject:notification.options.id];
}
return triggeredNotificationIds;
return ids;
}
/**
......@@ -113,22 +113,24 @@
*/
- (NSArray*) scheduledLocalNotificationIds
{
NSArray* scheduledNotifications = self.scheduledLocalNotifications;
NSMutableArray* scheduledNotificationIds = [[NSMutableArray alloc] init];
NSArray* notifications = self.scheduledLocalNotifications;
NSMutableArray* ids = [[NSMutableArray alloc] init];
for (UILocalNotification* notification in scheduledNotifications)
{
if (notification)
for (UILocalNotification* notification in notifications)
{
[scheduledNotificationIds addObject:notification.options.id];
if (notification) {
[ids addObject:notification.options.id];
}
}
return scheduledNotificationIds;
return ids;
}
/**
* Get the scheduled local notification by ID.
*
* @param id
* Notification ID
*/
- (UILocalNotification*) scheduledLocalNotificationWithId:(NSString*)id
{
......@@ -136,8 +138,7 @@
for (UILocalNotification* notification in notifications)
{
if (notification && [notification.options.id isEqualToString:id])
{
if (notification && [notification.options.id isEqualToString:id]) {
return notification;
}
}
......@@ -147,6 +148,9 @@
/**
* Get the triggered local notification by ID.
*
* @param id
* Notification ID
*/
- (UILocalNotification*) triggeredLocalNotificationWithId:(NSString*)id
{
......@@ -159,4 +163,84 @@
return NULL;
}
/**
* List of properties from all scheduled notifications.
*/
- (NSArray*) scheduledLocalNotificationOptions
{
NSArray* notifications = self.scheduledLocalNotifications;
NSMutableArray* options = [[NSMutableArray alloc] init];
for (UILocalNotification* notification in notifications)
{
if (notification) {
[options addObject:notification.userInfo];
}
}
return options;
}
/**
* List of properties from given scheduled notifications.
*
* @param ids
* Notification IDs
*/
- (NSArray*) scheduledLocalNotificationOptions:(NSArray*)ids
{
UILocalNotification* notification;
NSMutableArray* options = [[NSMutableArray alloc] init];
for (NSString* id in ids)
{
notification = [self scheduledLocalNotificationWithId:id];
if (notification) {
[options addObject:notification.userInfo];
}
}
return options;
}
/**
* List of properties from all triggered notifications.
*/
- (NSArray*) triggeredLocalNotificationOptions
{
NSArray* notifications = self.triggeredLocalNotifications;
NSMutableArray* options = [[NSMutableArray alloc] init];
for (UILocalNotification* notification in notifications)
{
[options addObject:notification.userInfo];
}
return options;
}
/**
* List of properties from given triggered notifications.
*
* @param ids
* Notification IDs
*/
- (NSArray*) triggeredLocalNotificationOptions:(NSArray*)ids
{
UILocalNotification* notification;
NSMutableArray* options = [[NSMutableArray alloc] init];
for (NSString* id in ids)
{
notification = [self triggeredLocalNotificationWithId:id];
if (notification) {
[options addObject:notification.userInfo];
}
}
return options;
}
@end
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