Commit 16a1b765 by Sebastián Katzer

JS Callbacks werden aufgerufen

parent 6bee7c55
...@@ -16,6 +16,8 @@ ...@@ -16,6 +16,8 @@
- (NSDictionary*) userDict:(NSMutableDictionary*)options; - (NSDictionary*) userDict:(NSMutableDictionary*)options;
- (UILocalNotification*) prepareNotification:(NSMutableDictionary*)options; - (UILocalNotification*) prepareNotification:(NSMutableDictionary*)options;
- (void)aWindowBecameMain:(NSNotification *)notification;
@end @end
...@@ -48,10 +50,12 @@ ...@@ -48,10 +50,12 @@
NSString *notificationId = [arguments objectAtIndex:0]; NSString *notificationId = [arguments objectAtIndex:0];
NSArray *notifications = [[UIApplication sharedApplication] scheduledLocalNotifications]; NSArray *notifications = [[UIApplication sharedApplication] scheduledLocalNotifications];
for (UILocalNotification *notification in notifications) { for (UILocalNotification *notification in notifications)
{
NSString *notId = [notification.userInfo objectForKey:@"notificationId"]; NSString *notId = [notification.userInfo objectForKey:@"notificationId"];
if ([notificationId isEqualToString:notId]) { if ([notificationId isEqualToString:notId])
{
[[UIApplication sharedApplication] cancelLocalNotification:notification]; [[UIApplication sharedApplication] cancelLocalNotification:notification];
} }
} }
...@@ -86,13 +90,11 @@ ...@@ -86,13 +90,11 @@
*/ */
- (NSDictionary*) userDict:(NSMutableDictionary*)options - (NSDictionary*) userDict:(NSMutableDictionary*)options
{ {
NSString *notificationId = [options objectForKey:@"id"]; NSString* id = [options objectForKey:@"id"];
NSString *bg = [options objectForKey:@"background"]; NSString* bg = [options objectForKey:@"background"];
NSString *fg = [options objectForKey:@"foreground"]; NSString* fg = [options objectForKey:@"foreground"];
NSDictionary *userDict = [NSDictionary dictionaryWithObjectsAndKeys:notificationId, @"notificationId", bg, @"background", fg, @"foreground", nil];
return userDict; return [NSDictionary dictionaryWithObjectsAndKeys:id, @"id", bg, @"background", fg, @"foreground", nil];
} }
/** /**
...@@ -115,7 +117,7 @@ ...@@ -115,7 +117,7 @@
notification.hasAction = hasAction; notification.hasAction = hasAction;
notification.timeZone = [NSTimeZone defaultTimeZone]; notification.timeZone = [NSTimeZone defaultTimeZone];
notification.repeatInterval = [[[self repeatDict] objectForKey: repeat] intValue]; notification.repeatInterval = [[[self repeatDict] objectForKey: repeat] intValue];
notification.alertBody = ([msg isEqualToString:@""])?nil:msg; notification.alertBody = ([msg isEqualToString:@""]) ? nil : msg;
notification.alertAction = action; notification.alertAction = action;
notification.soundName = sound; notification.soundName = sound;
notification.applicationIconBadgeNumber = badge; notification.applicationIconBadgeNumber = badge;
...@@ -123,4 +125,34 @@ ...@@ -123,4 +125,34 @@
return notification; 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;
NSString* id = [notification.userInfo objectForKey:@"id"];
NSString* callbackFn = [notification.userInfo objectForKey:isActive ? @"foreground" : @"background"];
if (callbackFn.length > 0)
{
NSString* jsCallBack = [NSString stringWithFormat:@"%@(%@)", callbackFn, id];
[self writeJavascript:jsCallBack];
}
}
/**
* @private
* Registriert den Observer für LocalNotification Events.
*/
- (void) pluginInitialize
{
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didReceiveLocalNotification:) name:CDVLocalNotification object:nil];
}
@end @end
\ No newline at end of file
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