Commit f918b56f authored by Libin Lu's avatar Libin Lu Committed by GitHub

backward compatible for addListener

parent 11a6acfe
......@@ -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];
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment