diff --git a/ios/RNFIRMessaging.m b/ios/RNFIRMessaging.m index e5724056b058d105801c9ca4e730e9a0eb011740..507b975eacaead3c045099c8157b65d5b3016059 100644 --- a/ios/RNFIRMessaging.m +++ b/ios/RNFIRMessaging.m @@ -217,26 +217,7 @@ RCT_MULTI_ENUM_CONVERTER(UNNotificationCategoryOptions, (@{ @end -@interface RNFIRMessagingHelper : NSObject - -@property (nonatomic, retain) NSDictionary *lastNotificationResponse; - -+ (nonnull instancetype) sharedInstance; - -@end - -@implementation RNFIRMessagingHelper - -+ (nonnull instancetype)sharedInstance { - static RNFIRMessagingHelper *sharedInstance = nil; - static dispatch_once_t onceToken; - dispatch_once(&onceToken, ^{ - sharedInstance = [self new]; - }); - return sharedInstance; -} - -@end +static NSDictionary *initialNotificationActionResponse; @interface RNFIRMessaging () @property (nonatomic, strong) NSMutableDictionary *notificationCallbacks; @@ -282,8 +263,14 @@ RCT_EXPORT_MODULE(); } NSDictionary *userInfo = @{@"data": data, @"completionHandler": completionHandler}; - [RNFIRMessagingHelper sharedInstance].lastNotificationResponse = userInfo; - + + static dispatch_once_t onceToken; + dispatch_once(&onceToken, ^{ + if (data[@"_actionIdentifier"] && ![data[@"_actionIdentifier"] isEqualToString:UNNotificationDefaultActionIdentifier]) { + initialNotificationActionResponse = userInfo; + } + }); + [[NSNotificationCenter defaultCenter] postNotificationName:FCMNotificationReceived object:self userInfo:userInfo]; } @@ -325,9 +312,11 @@ RCT_EXPORT_MODULE(); return self; } --(void)startObserving { - if([RNFIRMessagingHelper sharedInstance].lastNotificationResponse) { - [[NSNotificationCenter defaultCenter] postNotificationName:FCMNotificationReceived object:self userInfo:[RNFIRMessagingHelper sharedInstance].lastNotificationResponse]; +-(void) addListener:(NSString *)eventName { + [super addListener:eventName]; + + if([eventName isEqualToString:FCMNotificationReceived] && initialNotificationActionResponse) { + [[NSNotificationCenter defaultCenter] postNotificationName:FCMNotificationReceived object:self userInfo:[initialNotificationActionResponse copy]]; } } @@ -351,6 +340,8 @@ RCT_EXPORT_METHOD(getInitialNotification:(RCTPromiseResolveBlock)resolve rejecte } } + + RCT_EXPORT_METHOD(getAPNSToken:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) { NSData * deviceToken = [FIRMessaging messaging].APNSToken; @@ -627,8 +618,10 @@ RCT_EXPORT_METHOD(finishNotificationResponse: (NSString *)completionHandlerId){ } [self sendEventWithName:FCMNotificationReceived body:data]; - - [RNFIRMessagingHelper sharedInstance].lastNotificationResponse = nil; + + if (initialNotificationActionResponse) { + initialNotificationActionResponse = nil; + } } - (void)sendDataMessageFailure:(NSNotification *)notification