From a049e2e62d7607741bf15e3684b67b49a199535c Mon Sep 17 00:00:00 2001 From: zhangqinghe Date: Fri, 10 Apr 2015 11:04:56 +0800 Subject: [PATCH] add open notificaiton event when app run background --- example/index.html | 17 ++++++++--------- src/ios/Plugins/JPushPlugin.m | 26 +++++++++++++++++++++++--- 2 files changed, 31 insertions(+), 12 deletions(-) diff --git a/example/index.html b/example/index.html index 8701c77..9acfc84 100644 --- a/example/index.html +++ b/example/index.html @@ -27,15 +27,14 @@ } } var onOpenNotification = function(event){ - try{ - var alert = event.alert; - var extras = event.extras; - console.log(alert); - //console.log(extras); - } - catch(exeption){ - console.log(exception) - } + try{ + + var alert = event.aps.alert; + console.log("JPushPlugin:onPpenNotification key aps.alert:"+alert); + } + catch(exception){ + console.log("JPushPlugin:onPpenNotification"+exception); + } } var onReceiveNotification = function(event){ try{ diff --git a/src/ios/Plugins/JPushPlugin.m b/src/ios/Plugins/JPushPlugin.m index 680c140..0697040 100644 --- a/src/ios/Plugins/JPushPlugin.m +++ b/src/ios/Plugins/JPushPlugin.m @@ -8,6 +8,7 @@ #import "JPushPlugin.h" #import "APService.h" +#import @implementation JPushPlugin @@ -275,10 +276,29 @@ NSData *jsonData = [NSJSONSerialization dataWithJSONObject:userInfo options:0 error:&error]; NSString *jsonString = [[NSString alloc]initWithData:jsonData encoding:NSUTF8StringEncoding]; + switch ([UIApplication sharedApplication].applicationState) { + case UIApplicationStateActive: + { + dispatch_async(dispatch_get_main_queue(), ^{ + [self.commandDelegate evalJs:[NSString stringWithFormat:@"cordova.fireDocumentEvent('jpush.receiveNotification',%@)",jsonString]]; + }); + + } + break; + case UIApplicationStateInactive: + case UIApplicationStateBackground: + { + dispatch_async(dispatch_get_main_queue(), ^{ + [self.commandDelegate evalJs:[NSString stringWithFormat:@"cordova.fireDocumentEvent('jpush.openNotification',%@)",jsonString]]; + }); + + } + break; + default: + //do nothing + break; + } - dispatch_async(dispatch_get_main_queue(), ^{ - [self.commandDelegate evalJs:[NSString stringWithFormat:@"cordova.fireDocumentEvent('jpush.receiveNotification',%@)",jsonString]]; - }); }