From 27c4fe7b260748c4aa2f0f691ab705af01198c3e Mon Sep 17 00:00:00 2001 From: zhangqinghe Date: Tue, 10 Mar 2015 16:46:44 +0800 Subject: [PATCH] add event jpush.receiveNotification in object-c file --- src/ios/Plugins/JPushPlugin.m | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/ios/Plugins/JPushPlugin.m b/src/ios/Plugins/JPushPlugin.m index 648880d..ca531d9 100644 --- a/src/ios/Plugins/JPushPlugin.m +++ b/src/ios/Plugins/JPushPlugin.m @@ -19,6 +19,11 @@ selector:@selector(networkDidReceiveMessage:) name:kJPFNetworkDidReceiveMessageNotification object:nil]; + + [defaultCenter addObserver:self + selector:@selector(networkDidReceiveNotification:) + name:kJPushPluginReceiveNotification + object:nil]; } @@ -195,13 +200,13 @@ - (void)networkDidReceiveMessage:(NSNotification *)notification { NSDictionary *userInfo = [notification userInfo]; - NSLog(@"%@",userInfo); + //NSLog(@"%@",userInfo); NSError *error; NSData *jsonData = [NSJSONSerialization dataWithJSONObject:userInfo options:0 error:&error]; NSString *jsonString = [[NSString alloc]initWithData:jsonData encoding:NSUTF8StringEncoding]; - NSLog(@"%@",jsonString); + //NSLog(@"%@",jsonString); dispatch_async(dispatch_get_main_queue(), ^{ @@ -211,4 +216,19 @@ } +-(void)networkDidReceiveNotification:(id)notification{ + + NSError *error; + NSDictionary *userInfo = [notification object]; + + NSData *jsonData = [NSJSONSerialization dataWithJSONObject:userInfo options:0 error:&error]; + NSString *jsonString = [[NSString alloc]initWithData:jsonData encoding:NSUTF8StringEncoding]; + + dispatch_async(dispatch_get_main_queue(), ^{ + [self.commandDelegate evalJs:[NSString stringWithFormat:@"cordova.fireDocumentEvent('jpush.receiveNotification',%@)",jsonString]]; + }); + +} + + @end