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] 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 {