Commit 16a1b765 authored by Sebastián Katzer's avatar Sebastián Katzer
Browse files

JS Callbacks werden aufgerufen

parent 6bee7c55
Loading
Loading
Loading
Loading
+38 −6
Changes for src/ios/APPLocalNotification.m: 38 added lines, 6 removed lines.
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@
- (NSDictionary*) userDict:(NSMutableDictionary*)options;
- (UILocalNotification*) prepareNotification:(NSMutableDictionary*)options;

- (void)aWindowBecameMain:(NSNotification *)notification;

@end


@@ -48,10 +50,12 @@
	NSString *notificationId = [arguments objectAtIndex:0];
	NSArray  *notifications  = [[UIApplication sharedApplication] scheduledLocalNotifications];

	for (UILocalNotification *notification in notifications) {
	for (UILocalNotification *notification in notifications)
    {
		NSString *notId = [notification.userInfo objectForKey:@"notificationId"];

		if ([notificationId isEqualToString:notId]) {
		if ([notificationId isEqualToString:notId])
        {
			[[UIApplication sharedApplication] cancelLocalNotification:notification];
		}
	}
@@ -86,13 +90,11 @@
 */
- (NSDictionary*) userDict:(NSMutableDictionary*)options
{
	NSString     *notificationId = [options objectForKey:@"id"];
	NSString* id = [options objectForKey:@"id"];
    NSString* bg = [options objectForKey:@"background"];
    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];
}

/**
@@ -123,4 +125,34 @@
    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
 No newline at end of file