Commit 778bbbb9 authored by Bob Easterday's avatar Bob Easterday
Browse files

Surface custom key/value pairs to JS for iOS

parent 33459fc4
Loading
Loading
Loading
Loading
+2 −2
Changes for src/ios/AppDelegate+notification.m: 2 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -40,7 +40,7 @@ static char launchNotificationKey;
    
    if (appState == UIApplicationStateActive) {
        PushPlugin *pushHandler = [self getCommandInstance:@"PushPlugin"];
        pushHandler.notificationMessage = [userInfo objectForKey:@"aps"];
        pushHandler.notificationMessage = userInfo;
        pushHandler.isInline = YES;
        [pushHandler notificationReceived];
    } else {
@@ -58,7 +58,7 @@ static char launchNotificationKey;

    if (![self.viewController.webView isLoading] && self.launchNotification) {
        PushPlugin *pushHandler = [self getCommandInstance:@"PushPlugin"];
        pushHandler.notificationMessage = [self.launchNotification objectForKey:@"aps"];
        pushHandler.notificationMessage = self.launchNotification;
        
        self.launchNotification = nil;
        
+22 −9
Changes for src/ios/PushPlugin.m: 22 added lines, 9 removed lines.
Original line number Diff line number Diff line
@@ -156,15 +156,12 @@

- (void)notificationReceived {
    NSLog(@"Notification received");
    NSLog(@"Msg: %@", [notificationMessage descriptionWithLocale:[NSLocale currentLocale] indent:4]);

    if (notificationMessage) {
    if (notificationMessage)
    {
        NSMutableString *jsonStr = [NSMutableString stringWithString:@"{"];
        if ([notificationMessage objectForKey:@"alert"])
            [jsonStr appendFormat:@"alert:'%@',", [[notificationMessage objectForKey:@"alert"] stringByReplacingOccurrencesOfString:@"'" withString:@"\\'"]];

        if ([notificationMessage objectForKey:@"badge"])
            [jsonStr appendFormat:@"badge:%d,", [[notificationMessage objectForKey:@"badge"] intValue]];
        [self parseDictionary:notificationMessage intoJSON:jsonStr];

        if (isInline)
        {
@@ -172,11 +169,10 @@
            isInline = NO;
        }
        
        if ([notificationMessage objectForKey:@"sound"])
            [jsonStr appendFormat:@"sound:'%@',", [notificationMessage objectForKey:@"sound"]];

        [jsonStr appendString:@"}"];

        NSLog(@"Msg: %@", jsonStr);

        NSString * jsCallBack = [NSString stringWithFormat:@"%@(%@);", self.callback, jsonStr];
        [self.webView stringByEvaluatingJavaScriptFromString:jsCallBack];
        
@@ -184,6 +180,23 @@
    }
}

// reentrant method to drill down and surface all sub-dictionaries' key/value pairs into the top level json
-(void)parseDictionary:(NSDictionary *)inDictionary intoJSON:(NSMutableString *)jsonString
{
    NSArray         *keys = [inDictionary allKeys];
    NSString        *key;
    
    for (key in keys)
    {
        id thisObject = [inDictionary objectForKey:key];
    
        if ([thisObject isKindOfClass:[NSDictionary class]])
            [self parseDictionary:thisObject intoJSON:jsonString];
        else
            [jsonString appendFormat:@"%@:'%@',", key, [inDictionary objectForKey:key]];
    }
}

- (void)setApplicationIconBadgeNumber:(NSMutableArray *)arguments withDict:(NSMutableDictionary *)options {
	DLog(@"setApplicationIconBadgeNumber:%@\n withDict:%@", arguments, options);