add open notification evnet when app is launching

This commit is contained in:
zhangqinghe 2015-04-10 13:42:25 +08:00
parent 2dbd0cb248
commit ff86dc1230
2 changed files with 23 additions and 0 deletions

View File

@ -14,6 +14,7 @@
}
+(void)setLaunchOptions:(NSDictionary *)theLaunchOptions;
-(void)setTagsWithAlias:(CDVInvokedUrlCommand*)command;
-(void)setTags:(CDVInvokedUrlCommand*)command;
-(void)setAlias:(CDVInvokedUrlCommand*)command;

View File

@ -10,8 +10,16 @@
#import "APService.h"
#import <UIKit/UIKit.h>
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;
}