add jpush event cache

This commit is contained in:
huangminlinux 2017-10-23 17:11:18 +08:00
parent 66932a8bc8
commit 3129165d3f
3 changed files with 26 additions and 1 deletions

View File

@ -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) {

View File

@ -8,6 +8,8 @@
#import <Cordova/CDV.h>
NSMutableDictionary *_jpushEventCache;
@interface JPushPlugin : CDVPlugin{
}

View File

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