Loading src/ios/APPLocalNotification.h +2 −3 Changes for src/ios/APPLocalNotification.h: 2 added lines, 3 removed lines. Original line number Diff line number Diff line /** * APPLocalNotification.h * Cordova LocalNotification Plugin * * Created by Sebastian Katzer (github.com/katzer) on 10/08/2013. * Created by Sebastian Katzer (github.com/katzer). * Copyright 2013 Sebastian Katzer. All rights reserved. * GPL v2 licensed * LGPL v2.1 licensed */ #import <Foundation/Foundation.h> Loading src/ios/APPLocalNotification.m +35 −26 Changes for src/ios/APPLocalNotification.m: 35 added lines, 26 removed lines. Original line number Diff line number Diff line /** * APPLocalNotification.m * Cordova LocalNotification Plugin * * Created by Sebastian Katzer (github.com/katzer) on 10/08/2013. * Created by Sebastian Katzer (github.com/katzer). * Copyright 2013 Sebastian Katzer. All rights reserved. * GPL v2 licensed * LGPL v2.1 licensed */ #import "APPLocalNotification.h" @interface APPLocalNotification (Private) - (NSMutableDictionary*) repeatDict; // Alle zusätzlichen Metadaten der Notification als Hash - (NSDictionary*) userDict:(NSMutableDictionary*)options; - (UILocalNotification*) prepareNotification:(NSMutableDictionary*)options; // Erstellt die Notification und setzt deren Eigenschaften - (UILocalNotification*) notificationWithProperties:(NSMutableDictionary*)options; // Ruft die JS-Callbacks auf, nachdem eine Notification eingegangen ist - (void) didReceiveLocalNotification:(NSNotification*)localNotification; @end Loading @@ -25,16 +26,14 @@ /** * Fügt eine neue Notification-Eintrag hinzu. * * @param {NSMutableDictionary} options * @param {NSMutableDictionary} options Die Eigenschaften der Notification */ - (void) add:(CDVInvokedUrlCommand*)command { [self.commandDelegate runInBackground:^{ NSArray* arguments = [command arguments]; NSMutableDictionary* options = [arguments objectAtIndex:0]; UILocalNotification *notification = [self prepareNotification:options]; notification.userInfo = [self userDict:options]; UILocalNotification* notification = [self notificationWithProperties:options]; [[UIApplication sharedApplication] scheduleLocalNotification:notification]; }]; Loading Loading @@ -87,7 +86,7 @@ } /** * @private * Alle zusätzlichen Metadaten der Notification als Hash. */ - (NSDictionary*) userDict:(NSMutableDictionary*)options { Loading @@ -99,10 +98,9 @@ } /** * @private * Erstellt die Notification und setzt deren Eigenschaften. */ - (UILocalNotification*) prepareNotification:(NSMutableDictionary*)options - (UILocalNotification*) notificationWithProperties:(NSMutableDictionary*)options { UILocalNotification* notification = [[UILocalNotification alloc] init]; Loading @@ -111,53 +109,64 @@ NSString* title = [options objectForKey:@"title"]; NSString* sound = [options objectForKey:@"sound"]; NSString* repeat = [options objectForKey:@"repeat"]; bool hasAction = ([[options objectForKey:@"hasAction"] intValue] == 1)?YES:NO; NSInteger badge = [[options objectForKey:@"badge"] intValue]; NSDate* date = [NSDate dateWithTimeIntervalSince1970:timestamp]; notification.fireDate = date; notification.fireDate = [NSDate dateWithTimeIntervalSince1970:timestamp]; notification.timeZone = [NSTimeZone defaultTimeZone]; notification.repeatInterval = [[[self repeatDict] objectForKey: repeat] intValue]; notification.userInfo = [self userDict:options]; notification.applicationIconBadgeNumber = badge; if (![msg isEqualToString:@""]) { notification.alertBody = title ? [NSString stringWithFormat:@"%@\n%@", title, msg] : msg; if (title) { notification.alertBody = [NSString stringWithFormat:@"%@\n%@", title, msg]; } else { notification.alertBody = msg; } } if (sound != (NSString*)[NSNull null]) { notification.soundName = [sound isEqualToString:@""] ? UILocalNotificationDefaultSoundName : sound; if ([sound isEqualToString:@""]) { notification.soundName = UILocalNotificationDefaultSoundName; } else { notification.soundName = sound; } } notification.hasAction = hasAction; notification.applicationIconBadgeNumber = badge; return notification; } /** * @private * Ruft die JS-Callbacks auf, nachdem eine Notification eingegangen ist. */ - (void) didReceiveLocalNotification:(NSNotification*)localNotification { UILocalNotification* notification = [localNotification object]; UIApplicationState state = [[UIApplication sharedApplication] applicationState]; bool isActive = state == UIApplicationStateActive; UILocalNotification* notification = [localNotification object]; NSString* id = [notification.userInfo objectForKey:@"id"]; NSString* callbackFn = [notification.userInfo objectForKey:isActive ? @"foreground" : @"background"]; NSString* callbackType = isActive ? @"foreground" : @"background"; NSString* callbackFn = [notification.userInfo objectForKey:callbackType]; if (callbackFn.length > 0) { NSString* jsCallBack = [NSString stringWithFormat:@"setTimeout('%@(%@)',0)", callbackFn, id]; NSString* callback = [NSString stringWithFormat:@"setTimeout('%@(%@)',0)", callbackFn, id]; [self writeJavascript:jsCallBack]; [self writeJavascript:callback]; } } /** * @private * Registriert den Observer für LocalNotification Events. */ - (void) pluginInitialize Loading Loading
src/ios/APPLocalNotification.h +2 −3 Changes for src/ios/APPLocalNotification.h: 2 added lines, 3 removed lines. Original line number Diff line number Diff line /** * APPLocalNotification.h * Cordova LocalNotification Plugin * * Created by Sebastian Katzer (github.com/katzer) on 10/08/2013. * Created by Sebastian Katzer (github.com/katzer). * Copyright 2013 Sebastian Katzer. All rights reserved. * GPL v2 licensed * LGPL v2.1 licensed */ #import <Foundation/Foundation.h> Loading
src/ios/APPLocalNotification.m +35 −26 Changes for src/ios/APPLocalNotification.m: 35 added lines, 26 removed lines. Original line number Diff line number Diff line /** * APPLocalNotification.m * Cordova LocalNotification Plugin * * Created by Sebastian Katzer (github.com/katzer) on 10/08/2013. * Created by Sebastian Katzer (github.com/katzer). * Copyright 2013 Sebastian Katzer. All rights reserved. * GPL v2 licensed * LGPL v2.1 licensed */ #import "APPLocalNotification.h" @interface APPLocalNotification (Private) - (NSMutableDictionary*) repeatDict; // Alle zusätzlichen Metadaten der Notification als Hash - (NSDictionary*) userDict:(NSMutableDictionary*)options; - (UILocalNotification*) prepareNotification:(NSMutableDictionary*)options; // Erstellt die Notification und setzt deren Eigenschaften - (UILocalNotification*) notificationWithProperties:(NSMutableDictionary*)options; // Ruft die JS-Callbacks auf, nachdem eine Notification eingegangen ist - (void) didReceiveLocalNotification:(NSNotification*)localNotification; @end Loading @@ -25,16 +26,14 @@ /** * Fügt eine neue Notification-Eintrag hinzu. * * @param {NSMutableDictionary} options * @param {NSMutableDictionary} options Die Eigenschaften der Notification */ - (void) add:(CDVInvokedUrlCommand*)command { [self.commandDelegate runInBackground:^{ NSArray* arguments = [command arguments]; NSMutableDictionary* options = [arguments objectAtIndex:0]; UILocalNotification *notification = [self prepareNotification:options]; notification.userInfo = [self userDict:options]; UILocalNotification* notification = [self notificationWithProperties:options]; [[UIApplication sharedApplication] scheduleLocalNotification:notification]; }]; Loading Loading @@ -87,7 +86,7 @@ } /** * @private * Alle zusätzlichen Metadaten der Notification als Hash. */ - (NSDictionary*) userDict:(NSMutableDictionary*)options { Loading @@ -99,10 +98,9 @@ } /** * @private * Erstellt die Notification und setzt deren Eigenschaften. */ - (UILocalNotification*) prepareNotification:(NSMutableDictionary*)options - (UILocalNotification*) notificationWithProperties:(NSMutableDictionary*)options { UILocalNotification* notification = [[UILocalNotification alloc] init]; Loading @@ -111,53 +109,64 @@ NSString* title = [options objectForKey:@"title"]; NSString* sound = [options objectForKey:@"sound"]; NSString* repeat = [options objectForKey:@"repeat"]; bool hasAction = ([[options objectForKey:@"hasAction"] intValue] == 1)?YES:NO; NSInteger badge = [[options objectForKey:@"badge"] intValue]; NSDate* date = [NSDate dateWithTimeIntervalSince1970:timestamp]; notification.fireDate = date; notification.fireDate = [NSDate dateWithTimeIntervalSince1970:timestamp]; notification.timeZone = [NSTimeZone defaultTimeZone]; notification.repeatInterval = [[[self repeatDict] objectForKey: repeat] intValue]; notification.userInfo = [self userDict:options]; notification.applicationIconBadgeNumber = badge; if (![msg isEqualToString:@""]) { notification.alertBody = title ? [NSString stringWithFormat:@"%@\n%@", title, msg] : msg; if (title) { notification.alertBody = [NSString stringWithFormat:@"%@\n%@", title, msg]; } else { notification.alertBody = msg; } } if (sound != (NSString*)[NSNull null]) { notification.soundName = [sound isEqualToString:@""] ? UILocalNotificationDefaultSoundName : sound; if ([sound isEqualToString:@""]) { notification.soundName = UILocalNotificationDefaultSoundName; } else { notification.soundName = sound; } } notification.hasAction = hasAction; notification.applicationIconBadgeNumber = badge; return notification; } /** * @private * Ruft die JS-Callbacks auf, nachdem eine Notification eingegangen ist. */ - (void) didReceiveLocalNotification:(NSNotification*)localNotification { UILocalNotification* notification = [localNotification object]; UIApplicationState state = [[UIApplication sharedApplication] applicationState]; bool isActive = state == UIApplicationStateActive; UILocalNotification* notification = [localNotification object]; NSString* id = [notification.userInfo objectForKey:@"id"]; NSString* callbackFn = [notification.userInfo objectForKey:isActive ? @"foreground" : @"background"]; NSString* callbackType = isActive ? @"foreground" : @"background"; NSString* callbackFn = [notification.userInfo objectForKey:callbackType]; if (callbackFn.length > 0) { NSString* jsCallBack = [NSString stringWithFormat:@"setTimeout('%@(%@)',0)", callbackFn, id]; NSString* callback = [NSString stringWithFormat:@"setTimeout('%@(%@)',0)", callbackFn, id]; [self writeJavascript:jsCallBack]; [self writeJavascript:callback]; } } /** * @private * Registriert den Observer für LocalNotification Events. */ - (void) pluginInitialize Loading