Commit ed78cdfb authored by PKnittel's avatar PKnittel
Browse files
parents 16a38ade d8a4f573
Loading
Loading
Loading
Loading
+1 −0
Changes for plugin.xml: 1 added line, 0 removed lines.
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@
    <dependency id="org.apache.cordova.device" url="https://github.com/apache/cordova-plugin-device" />

    <js-module src="www/local-notification.js" name="LocalNotification">
        <clobbers target="cordova.plugins.notification.local" />
        <clobbers target="plugin.notification.local" />
    </js-module>

+19 −8
Changes for src/ios/APPLocalNotification.h: 19 added lines, 8 removed lines.
Original line number Diff line number Diff line
@@ -26,6 +26,12 @@

// Execute all queued events
- (void) deviceready:(CDVInvokedUrlCommand*)command;

// Inform if the app has the permission to show notifications
- (void) hasPermission:(CDVInvokedUrlCommand*)command;
// Register permission to show notifications
- (void) registerPermission:(CDVInvokedUrlCommand*)command;

// Schedule a new notification
- (void) add:(CDVInvokedUrlCommand*)command;
// Update a notification
@@ -34,21 +40,26 @@
- (void) cancel:(CDVInvokedUrlCommand*)command;
// Cancel all currently scheduled notifications
- (void) cancelAll:(CDVInvokedUrlCommand*)command;
// Check if a notification with an ID is scheduled

// If a notification with an ID exists
- (void) exist:(CDVInvokedUrlCommand*)command;
// If a notification with an ID was scheduled
- (void) isScheduled:(CDVInvokedUrlCommand*)command;
// Check if a notification with an ID was triggered
// If a notification with an ID was triggered
- (void) isTriggered:(CDVInvokedUrlCommand*)command;

// List all ids from all local notifications
- (void) getAllIds:(CDVInvokedUrlCommand*)command;
// List all ids from all pending notifications
- (void) getScheduledIds:(CDVInvokedUrlCommand*)command;
// List all ids from all triggered notifications
- (void) getTriggeredIds:(CDVInvokedUrlCommand*)command;
// List all properties for given scheduled notifications

// Property list for given local notifications
- (void) getAll:(CDVInvokedUrlCommand*)command;
// Property list for given scheduled notifications
- (void) getScheduled:(CDVInvokedUrlCommand*)command;
// List all properties for given triggered notifications
// Property list 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
- (void) registerPermission:(CDVInvokedUrlCommand*)command;

@end
+83 −3
Changes for src/ios/APPLocalNotification.m: 83 added lines, 3 removed lines.
Original line number Diff line number Diff line
@@ -161,6 +161,34 @@
    }];
}

/**
 * If a notification by ID exists.
 *
 * @param id
 *      The ID of the notification
 */
- (void) exist:(CDVInvokedUrlCommand *)command
{
    [self.commandDelegate runInBackground:^{
        NSString* id = [[command arguments]
                        objectAtIndex:0];

        CDVPluginResult* result;
        UILocalNotification* notification;

        notification = [[UIApplication sharedApplication]
                        localNotificationWithId:id];

        bool exists = notification != NULL;

        result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK
                                     messageAsBool:exists];

        [self.commandDelegate sendPluginResult:result
                                    callbackId:command.callbackId];
    }];
}

/**
 * If a notification by ID is scheduled.
 *
@@ -217,6 +245,26 @@
    }];
}

/**
 * List all ids from all local notifications.
 */
- (void) getAllIds:(CDVInvokedUrlCommand*)command
{
    [self.commandDelegate runInBackground:^{
        CDVPluginResult* result;
        NSArray* notIds;

        notIds = [[UIApplication sharedApplication]
                  localNotificationIds];

        result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK
                                    messageAsArray:notIds];

        [self.commandDelegate sendPluginResult:result
                                    callbackId:command.callbackId];
    }];
}

/**
 * List all ids from all pending notifications.
 */
@@ -258,7 +306,36 @@
}

/**
 * List all properties for given scheduled notifications.
 * Property list for given local notifications.
 *
 * @param ids
 *      The IDs of the notifications
 */
- (void) getAll:(CDVInvokedUrlCommand*)command
{
    [self.commandDelegate runInBackground:^{
        NSArray* ids = command.arguments;
        NSArray* notifications;
        CDVPluginResult* result;

        if (ids.count == 0) {
            notifications = [[UIApplication sharedApplication]
                             localNotificationOptions];
        } else {
            notifications = [[UIApplication sharedApplication]
                             localNotificationOptions:ids];
        }

        result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK
                                    messageAsArray:notifications];

        [self.commandDelegate sendPluginResult:result
                                    callbackId:command.callbackId];
    }];
}

/**
 * Property list for given scheduled notifications.
 *
 * @param ids
 *      The IDs of the notifications
@@ -287,7 +364,7 @@
}

/**
 * List all properties for given triggered notifications.
 * Property list for given triggered notifications.
 *
 * @param ids
 *      The IDs of the notifications
@@ -604,13 +681,16 @@
        NSString* json = notification.options.json;
        NSString* args = [notification encodeToJSON];

        json = [json stringByReplacingOccurrencesOfString:@"'"
                                               withString:@"\\\\\\'"];

        params = [NSString stringWithFormat:
                  @"\"%@\",\"%@\",\\'%@\\',JSON.parse(\\'%@\\')",
                  id, self.applicationState, json, args];
    }

    js = [NSString stringWithFormat:
          @"setTimeout('plugin.notification.local.on%@(%@)',0)",
          @"setTimeout('cordova.plugins.notification.local.on%@(%@)',0)",
          event, params];

    if (deviceready) {
+20 −7
Changes for src/ios/UIApplication+APPLocalNotification.h: 20 added lines, 7 removed lines.
Original line number Diff line number Diff line
@@ -21,7 +21,11 @@

@interface UIApplication (APPLocalNotification)

@property (readonly, getter=localNotifications) NSArray* localNotifications;
@property (readonly, getter=scheduledLocalNotifications2) NSArray* triggeredLocalNotifications2;
@property (readonly, getter=triggeredLocalNotifications) NSArray* triggeredLocalNotifications;

@property (readonly, getter=localNotificationIds) NSArray* localNotificationIds;
@property (readonly, getter=triggeredLocalNotificationIds) NSArray* triggeredLocalNotificationIds;
@property (readonly, getter=scheduledLocalNotificationIds) NSArray* scheduledLocalNotificationIds;

@@ -29,17 +33,26 @@
- (BOOL) hasPermissionToScheduleLocalNotifications;
// Ask for permission to schedule local notifications
- (void) registerPermissionToScheduleLocalNotifications;
// Get the scheduled local notification by ID

// Get local notification by ID
- (UILocalNotification*) localNotificationWithId:(NSString*)id;
// Get scheduled local notification by ID
- (UILocalNotification*) scheduledLocalNotificationWithId:(NSString*)id;
// Get the triggered local notification by ID
// Get triggered local notification by ID
- (UILocalNotification*) triggeredLocalNotificationWithId:(NSString*)id;
// List of properties from all scheduled notifications

// Property list from all local notifications
- (NSArray*) localNotificationOptions;
// Property list from all scheduled notifications
- (NSArray*) scheduledLocalNotificationOptions;
// List of properties from given scheduled notifications
- (NSArray*) scheduledLocalNotificationOptions:(NSArray*)ids;
// List of properties from all triggered notifications
// Property list from all triggered notifications
- (NSArray*) triggeredLocalNotificationOptions;
// List of properties from given triggered notifications

// Property list from given local notifications
- (NSArray*) localNotificationOptions:(NSArray*)ids;
// Property list from given scheduled notifications
- (NSArray*) scheduledLocalNotificationOptions:(NSArray*)ids;
// Property list from given triggered notifications
- (NSArray*) triggeredLocalNotificationOptions:(NSArray*)ids;

@end
+131 −22
Changes for src/ios/UIApplication+APPLocalNotification.m: 131 added lines, 22 removed lines.
Original line number Diff line number Diff line
@@ -71,19 +71,56 @@
#pragma mark -
#pragma mark LocalNotifications

/**
 * List of all local notifications which have been added
 * but not yet removed from the notification center.
 */
- (NSArray*) localNotifications
{
    NSArray* scheduledNotifications = self.scheduledLocalNotifications;
    NSMutableArray* notifications = [[NSMutableArray alloc] init];

    for (UILocalNotification* notification in scheduledNotifications)
    {
        if (notification) {
            [notifications addObject:notification];
        }
    }

    return notifications;
}

/**
 * List of all local notifications which have been scheduled
 * and not yet removed from the notification center.
 */
- (NSArray*) scheduledLocalNotifications2
{
    NSArray* scheduledNotifications = self.scheduledLocalNotifications;
    NSMutableArray* notifications = [[NSMutableArray alloc] init];

    for (UILocalNotification* notification in scheduledNotifications)
    {
        if (notification && [notification wasScheduled]) {
            [notifications addObject:notification];
        }
    }

    return notifications;
}

/**
 * List of all triggered local notifications which have been scheduled
 * and not yet removed the notification center.
 */
- (NSArray*) triggeredLocalNotifications
{
    NSArray* scheduledNotifications = self.scheduledLocalNotifications;
    NSArray* notifications = self.localNotifications;
    NSMutableArray* triggeredNotifications = [[NSMutableArray alloc] init];

    for (UILocalNotification* notification in scheduledNotifications)
    {
        if (notification && [notification wasTriggered])
    for (UILocalNotification* notification in notifications)
    {
        if ([notification wasTriggered]) {
            [triggeredNotifications addObject:notification];
        }
    }
@@ -93,7 +130,24 @@

/**
 * List of all triggered local notifications IDs which have been scheduled
 * and not yet removed the notification center.
 * and not yet removed from the notification center.
 */
- (NSArray*) localNotificationIds
{
    NSArray* notifications = self.localNotifications;
    NSMutableArray* ids = [[NSMutableArray alloc] init];

    for (UILocalNotification* notification in notifications)
    {
        [ids addObject:notification.options.id];
    }

    return ids;
}

/**
 * List of all added local notifications IDs which have been scheduled
 * and not yet removed from the notification center.
 */
- (NSArray*) triggeredLocalNotificationIds
{
@@ -113,32 +167,50 @@
 */
- (NSArray*) scheduledLocalNotificationIds
{
    NSArray* notifications = self.scheduledLocalNotifications;
    NSArray* notifications = self.scheduledLocalNotifications2;
    NSMutableArray* ids = [[NSMutableArray alloc] init];

    for (UILocalNotification* notification in notifications)
    {
        if (notification) {
        [ids addObject:notification.options.id];
    }
    }

    return ids;
}

/**
 * Get the scheduled local notification by ID.
 * Get local notification by ID.
 *
 * @param id
 *      Notification ID
 */
- (UILocalNotification*) localNotificationWithId:(NSString*)id
{
    NSArray* notifications = self.localNotifications;

    for (UILocalNotification* notification in notifications)
    {
        if ([notification.options.id isEqualToString:id]) {
            return notification;
        }
    }

    return NULL;
}

/**
 * Get scheduled local notification by ID.
 *
 * @param id
 *      Notification ID
 */
- (UILocalNotification*) scheduledLocalNotificationWithId:(NSString*)id
{
    NSArray* notifications = self.scheduledLocalNotifications;
    NSArray* notifications = self.scheduledLocalNotifications2;

    for (UILocalNotification* notification in notifications)
    {
        if (notification && [notification.options.id isEqualToString:id]) {
        if ([notification.options.id isEqualToString:id]) {
            return notification;
        }
    }
@@ -147,14 +219,14 @@
}

/**
 * Get the triggered local notification by ID.
 * Get triggered local notification by ID.
 *
 * @param id
 *      Notification ID
 */
- (UILocalNotification*) triggeredLocalNotificationWithId:(NSString*)id
{
    UILocalNotification* notification = [self scheduledLocalNotificationWithId:id];
    UILocalNotification* notification = [self localNotificationWithId:id];

    if (notification && [notification wasTriggered]) {
        return notification;
@@ -163,38 +235,68 @@
    return NULL;
}

/**
 * List of properties from all notifications.
 */
- (NSArray*) localNotificationOptions
{
    NSArray* notifications = self.localNotifications;
    NSMutableArray* options = [[NSMutableArray alloc] init];

    for (UILocalNotification* notification in notifications)
    {
        [options addObject:notification.userInfo];
    }

    return options;
}

/**
 * List of properties from all scheduled notifications.
 */
- (NSArray*) scheduledLocalNotificationOptions
{
    NSArray* notifications = self.scheduledLocalNotifications;
    NSArray* notifications = [self scheduledLocalNotifications2];
    NSMutableArray* options = [[NSMutableArray alloc] init];

    for (UILocalNotification* notification in notifications)
    {
        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 scheduled notifications.
 * List of properties from given local notifications.
 *
 * @param ids
 *      Notification IDs
 */
- (NSArray*) scheduledLocalNotificationOptions:(NSArray*)ids
- (NSArray*) localNotificationOptions:(NSArray*)ids
{
    UILocalNotification* notification;
    NSMutableArray* options = [[NSMutableArray alloc] init];

    for (NSString* id in ids)
    {
        notification = [self scheduledLocalNotificationWithId:id];
        notification = [self localNotificationWithId:id];

        if (notification) {
            [options addObject:notification.userInfo];
@@ -205,17 +307,24 @@
}

/**
 * List of properties from all triggered notifications.
 * List of properties from given scheduled notifications.
 *
 * @param ids
 *      Notification IDs
 */
- (NSArray*) triggeredLocalNotificationOptions
- (NSArray*) scheduledLocalNotificationOptions:(NSArray*)ids
{
    NSArray* notifications = self.triggeredLocalNotifications;
    UILocalNotification* notification;
    NSMutableArray* options = [[NSMutableArray alloc] init];

    for (UILocalNotification* notification in notifications)
    for (NSString* id in ids)
    {
        notification = [self scheduledLocalNotificationWithId:id];

        if (notification) {
            [options addObject:notification.userInfo];
        }
    }

    return options;
}
Loading