Commit c05a1750 authored by Krystof Celba's avatar Krystof Celba

Rewrite handling of actions when JS is not yet initialized.

We have to save initial notification action response
in case there isn't registered any FCMNotificationReceived
event handler yet. For example when the app is killed by a user
so JS has to be initialized first. The saved action
response will be sent to JS after first
FCMNotificationReceived event handler registered.
parent acf7ca1f
...@@ -217,26 +217,7 @@ RCT_MULTI_ENUM_CONVERTER(UNNotificationCategoryOptions, (@{ ...@@ -217,26 +217,7 @@ RCT_MULTI_ENUM_CONVERTER(UNNotificationCategoryOptions, (@{
@end @end
@interface RNFIRMessagingHelper : NSObject static NSDictionary *initialNotificationActionResponse;
@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
@interface RNFIRMessaging () @interface RNFIRMessaging ()
@property (nonatomic, strong) NSMutableDictionary *notificationCallbacks; @property (nonatomic, strong) NSMutableDictionary *notificationCallbacks;
...@@ -282,7 +263,13 @@ RCT_EXPORT_MODULE(); ...@@ -282,7 +263,13 @@ RCT_EXPORT_MODULE();
} }
NSDictionary *userInfo = @{@"data": data, @"completionHandler": completionHandler}; 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]; [[NSNotificationCenter defaultCenter] postNotificationName:FCMNotificationReceived object:self userInfo:userInfo];
} }
...@@ -325,9 +312,11 @@ RCT_EXPORT_MODULE(); ...@@ -325,9 +312,11 @@ RCT_EXPORT_MODULE();
return self; return self;
} }
-(void)startObserving { -(void) addListener:(NSString *)eventName {
if([RNFIRMessagingHelper sharedInstance].lastNotificationResponse) { [super addListener:eventName];
[[NSNotificationCenter defaultCenter] postNotificationName:FCMNotificationReceived object:self userInfo:[RNFIRMessagingHelper sharedInstance].lastNotificationResponse];
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 ...@@ -351,6 +340,8 @@ RCT_EXPORT_METHOD(getInitialNotification:(RCTPromiseResolveBlock)resolve rejecte
} }
} }
RCT_EXPORT_METHOD(getAPNSToken:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) RCT_EXPORT_METHOD(getAPNSToken:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
{ {
NSData * deviceToken = [FIRMessaging messaging].APNSToken; NSData * deviceToken = [FIRMessaging messaging].APNSToken;
...@@ -628,7 +619,9 @@ RCT_EXPORT_METHOD(finishNotificationResponse: (NSString *)completionHandlerId){ ...@@ -628,7 +619,9 @@ RCT_EXPORT_METHOD(finishNotificationResponse: (NSString *)completionHandlerId){
[self sendEventWithName:FCMNotificationReceived body:data]; [self sendEventWithName:FCMNotificationReceived body:data];
[RNFIRMessagingHelper sharedInstance].lastNotificationResponse = nil; if (initialNotificationActionResponse) {
initialNotificationActionResponse = nil;
}
} }
- (void)sendDataMessageFailure:(NSNotification *)notification - (void)sendDataMessageFailure:(NSNotification *)notification
......
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