From 3129165d3f96ed4a8a8a922494eecf91d81e542d Mon Sep 17 00:00:00 2001 From: huangminlinux <380108184@qq.com> Date: Mon, 23 Oct 2017 17:11:18 +0800 Subject: [PATCH 1/3] add jpush event cache --- src/ios/Plugins/AppDelegate+JPush.m | 4 ++++ src/ios/Plugins/JPushPlugin.h | 2 ++ src/ios/Plugins/JPushPlugin.m | 21 ++++++++++++++++++++- 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/ios/Plugins/AppDelegate+JPush.m b/src/ios/Plugins/AppDelegate+JPush.m index 82145c4..0448ab6 100644 --- a/src/ios/Plugins/AppDelegate+JPush.m +++ b/src/ios/Plugins/AppDelegate+JPush.m @@ -38,6 +38,10 @@ NSDictionary *_launchOptions; -(void)applicationDidLaunch:(NSNotification *)notification{ + if (!_jpushEventCache) { + _jpushEventCache = @{}.mutableCopy; + } + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(jpushSDKDidLoginNotification) name:kJPFNetworkDidLoginNotification object:nil]; if (notification) { diff --git a/src/ios/Plugins/JPushPlugin.h b/src/ios/Plugins/JPushPlugin.h index 2228d04..e7a2d03 100644 --- a/src/ios/Plugins/JPushPlugin.h +++ b/src/ios/Plugins/JPushPlugin.h @@ -8,6 +8,8 @@ #import +NSMutableDictionary *_jpushEventCache; + @interface JPushPlugin : CDVPlugin{ } diff --git a/src/ios/Plugins/JPushPlugin.m b/src/ios/Plugins/JPushPlugin.m index aab742a..7c0ae35 100644 --- a/src/ios/Plugins/JPushPlugin.m +++ b/src/ios/Plugins/JPushPlugin.m @@ -83,12 +83,31 @@ selector:@selector(receiveLocalNotification:) name:JPushDocumentEvent_ReceiveLocalNotification object:nil]; + [self dispatchJPushCacheEvent]; +} + +- (void)dispatchJPushCacheEvent { + for (NSString* key in _jpushEventCache) { + NSArray *evenList = _jpushEventCache[key]; + for (NSString *event in evenList) { + [JPushPlugin fireDocumentEvent:key jsString:event]; + } + } } +(void)fireDocumentEvent:(NSString*)eventName jsString:(NSString*)jsString{ + if (SharedJPushPlugin) { dispatch_async(dispatch_get_main_queue(), ^{ - [SharedJPushPlugin.commandDelegate evalJs:[NSString stringWithFormat:@"cordova.fireDocumentEvent('jpush.%@',%@)", eventName, jsString]]; + [SharedJPushPlugin.commandDelegate evalJs:[NSString stringWithFormat:@"cordova.fireDocumentEvent('jpush.%@',%@)", eventName, jsString]]; }); + return; + } + + if (!_jpushEventCache[eventName]) { + _jpushEventCache[eventName] = @[].mutableCopy; + } + + [_jpushEventCache[eventName] addObject: jsString]; } -(void)setTags:(CDVInvokedUrlCommand*)command { From d2f9959ae1428a84a9988546596716598676a6e5 Mon Sep 17 00:00:00 2001 From: huangminlinux <380108184@qq.com> Date: Mon, 23 Oct 2017 17:18:49 +0800 Subject: [PATCH 2/3] open notification event add to jpush event cache --- src/ios/Plugins/AppDelegate+JPush.m | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/src/ios/Plugins/AppDelegate+JPush.m b/src/ios/Plugins/AppDelegate+JPush.m index 0448ab6..b441a6d 100644 --- a/src/ios/Plugins/AppDelegate+JPush.m +++ b/src/ios/Plugins/AppDelegate+JPush.m @@ -28,29 +28,20 @@ return [self init_plus]; } --(void)fireOpenNotification:(NSTimer*)timer{ - if (SharedJPushPlugin) { - [JPushPlugin fireDocumentEvent:JPushDocumentEvent_OpenNotification jsString:[timer.userInfo toJsonString]]; - [timer invalidate]; - } -} - NSDictionary *_launchOptions; -(void)applicationDidLaunch:(NSNotification *)notification{ if (!_jpushEventCache) { _jpushEventCache = @{}.mutableCopy; } - + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(jpushSDKDidLoginNotification) name:kJPFNetworkDidLoginNotification object:nil]; if (notification) { if (notification.userInfo) { if ([notification.userInfo valueForKey:UIApplicationLaunchOptionsRemoteNotificationKey]) { - [NSTimer scheduledTimerWithTimeInterval:0.01 target:self selector:@selector(fireOpenNotification:) - userInfo:[notification.userInfo - valueForKey:UIApplicationLaunchOptionsRemoteNotificationKey] repeats:YES]; + [JPushPlugin fireDocumentEvent:JPushDocumentEvent_OpenNotification jsString:[notification.userInfo toJsonString]]; } if ([notification.userInfo valueForKey:UIApplicationLaunchOptionsLocalNotificationKey]) { @@ -60,7 +51,7 @@ NSDictionary *_launchOptions; @"badge": @(localNotification.applicationIconBadgeNumber), @"extras":localNotification.userInfo, }; - [NSTimer scheduledTimerWithTimeInterval:0.01 target:self selector:@selector(fireOpenNotification:) userInfo:localNotificationEvent repeats:YES]; + [JPushPlugin fireDocumentEvent:JPushDocumentEvent_OpenNotification jsString:[localNotificationEvent toJsonString]]; } } From fefaaea14f9a677d920f4020a76aa5c392253637 Mon Sep 17 00:00:00 2001 From: Hevin Date: Mon, 23 Oct 2017 17:22:53 +0800 Subject: [PATCH 3/3] build: v3.2.10 --- README.md | 2 +- package.json | 2 +- plugin.xml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index e81e2ac..d567166 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # JPush PhoneGap / Cordova Plugin [![Build Status](https://travis-ci.org/jpush/jpush-phonegap-plugin.svg?branch=master)](https://travis-ci.org/jpush/jpush-phonegap-plugin) -[![release](https://img.shields.io/badge/release-3.2.9-blue.svg)](https://github.com/jpush/jpush-phonegap-plugin/releases) +[![release](https://img.shields.io/badge/release-3.2.10-blue.svg)](https://github.com/jpush/jpush-phonegap-plugin/releases) [![platforms](https://img.shields.io/badge/platforms-iOS%7CAndroid-lightgrey.svg)](https://github.com/jpush/jpush-phonegap-plugin) [![weibo](https://img.shields.io/badge/weibo-JPush-blue.svg)](http://weibo.com/jpush?refer_flag=1001030101_&is_all=1) diff --git a/package.json b/package.json index 13f6591..08478d3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "jpush-phonegap-plugin", - "version": "3.2.9", + "version": "3.2.10", "description": "JPush for cordova plugin", "cordova": { "id": "jpush-phonegap-plugin", diff --git a/plugin.xml b/plugin.xml index d0eb210..d0d483d 100644 --- a/plugin.xml +++ b/plugin.xml @@ -2,7 +2,7 @@ + version="3.2.10"> JPush JPush for cordova plugin