From f918b56f692f00b487f1890a1aadbf319048034a Mon Sep 17 00:00:00 2001 From: Libin Lu Date: Sat, 24 Feb 2018 12:34:35 -0500 Subject: [PATCH] backward compatible for addListener --- ios/RNFIRMessaging.m | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/ios/RNFIRMessaging.m b/ios/RNFIRMessaging.m index 42540b0..360c838 100644 --- a/ios/RNFIRMessaging.m +++ b/ios/RNFIRMessaging.m @@ -217,6 +217,10 @@ RCT_MULTI_ENUM_CONVERTER(UNNotificationCategoryOptions, (@{ @end +@interface RCTEventEmitter () +- (void) addListener:(NSString *)eventName; +@end + @interface RNFIRMessaging () @property (nonatomic, strong) NSMutableDictionary *notificationCallbacks; @end @@ -318,6 +322,12 @@ RCT_EXPORT_MODULE(); [[FIRMessaging messaging] setDelegate:self]; }); + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(10 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ + if(!jsHandlerRegistered){ + [self sendPendingNotifications]; + } + }); + return self; } @@ -325,20 +335,24 @@ RCT_EXPORT_MODULE(); [super addListener:eventName]; if([eventName isEqualToString:FCMNotificationReceived]) { - static dispatch_once_t onceToken; - dispatch_once(&onceToken, ^{ - jsHandlerRegistered = true; - - for (NSDictionary* data in pendingNotifications) { - [[NSNotificationCenter defaultCenter] postNotificationName:FCMNotificationReceived object:self userInfo:data]; - } - - [pendingNotifications removeAllObjects]; - - }); + [self sendPendingNotifications]; } } +-(void) sendPendingNotifications { + static dispatch_once_t onceToken; + dispatch_once(&onceToken, ^{ + jsHandlerRegistered = true; + + for (NSDictionary* data in pendingNotifications) { + [[NSNotificationCenter defaultCenter] postNotificationName:FCMNotificationReceived object:self userInfo:data]; + } + + [pendingNotifications removeAllObjects]; + + }); +} + RCT_EXPORT_METHOD(enableDirectChannel) { [[FIRMessaging messaging] setShouldEstablishDirectChannel:@YES]; -- 2.26.2