From ff86dc12309779881b57378b8a2be8b7d9b9283b Mon Sep 17 00:00:00 2001 From: zhangqinghe Date: Fri, 10 Apr 2015 13:42:25 +0800 Subject: [PATCH] add open notification evnet when app is launching --- src/ios/Plugins/JPushPlugin.h | 1 + src/ios/Plugins/JPushPlugin.m | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/src/ios/Plugins/JPushPlugin.h b/src/ios/Plugins/JPushPlugin.h index 3f2d77f..605f420 100644 --- a/src/ios/Plugins/JPushPlugin.h +++ b/src/ios/Plugins/JPushPlugin.h @@ -14,6 +14,7 @@ } ++(void)setLaunchOptions:(NSDictionary *)theLaunchOptions; -(void)setTagsWithAlias:(CDVInvokedUrlCommand*)command; -(void)setTags:(CDVInvokedUrlCommand*)command; -(void)setAlias:(CDVInvokedUrlCommand*)command; diff --git a/src/ios/Plugins/JPushPlugin.m b/src/ios/Plugins/JPushPlugin.m index 0697040..6dd503d 100644 --- a/src/ios/Plugins/JPushPlugin.m +++ b/src/ios/Plugins/JPushPlugin.m @@ -10,8 +10,16 @@ #import "APService.h" #import +static NSDictionary *_luanchOptions=nil; + @implementation JPushPlugin + ++(void)setLaunchOptions:(NSDictionary *)theLaunchOptions{ + _luanchOptions=theLaunchOptions; + +} + - (CDVPlugin*)initWithWebView:(UIWebView*)theWebView{ if (self=[super initWithWebView:theWebView]) { @@ -26,7 +34,21 @@ name:kJPushPluginReceiveNotification object:nil]; + NSDictionary *userInfo = [_luanchOptions + valueForKey:UIApplicationLaunchOptionsRemoteNotificationKey]; + if (_luanchOptions && [userInfo count] >0) { + NSError *error; + NSData *jsonData = [NSJSONSerialization dataWithJSONObject:userInfo options:0 error:&error]; + NSString *jsonString = [[NSString alloc]initWithData:jsonData encoding:NSUTF8StringEncoding]; + if (!error) { + + dispatch_async(dispatch_get_main_queue(), ^{ + [self.commandDelegate evalJs:[NSString stringWithFormat:@"cordova.fireDocumentEvent('jpush.openNotification',%@)",jsonString]]; + }); + + } + } } return self; }