diff --git a/index.js b/index.js index 75db8e7692eaeba9a6bd5565ba011e9451d78d56..1d93879ccf43b6f58eb90dbc459ca497a27963a8 100644 --- a/index.js +++ b/index.js @@ -16,6 +16,13 @@ export const WillPresentNotificationResult = { None: 'UNNotificationPresentationOptionNone' } +export const NotificationType = { + Remote: 'remote_notification', + NotificationResponse: 'notification_response', + WillPresent: 'will_present_notification', + Local: 'local_notification' +} + const RNFIRMessaging = NativeModules.RNFIRMessaging; const FCM = {}; @@ -87,18 +94,18 @@ function finish(result){ } if(!this._finishCalled && this._completionHandlerId){ this._finishCalled = true; - switch(this.notification_event_type){ - case 'remote_notification': + switch(this._notificationType){ + case NotificationType.Remote: result = result || RemoteNotificationResult.NoData; if(!Object.values(RemoteNotificationResult).includes(result)){ throw new Error(`Invalid RemoteNotificationResult, use import {RemoteNotificationResult} from 'react-native-fcm' to avoid typo`); } RNFIRMessaging.finishRemoteNotification(this._completionHandlerId, result); return; - case 'notification_response': + case NotificationType.NotificationResponse: RNFIRMessaging.finishNotificationResponse(this._completionHandlerId); return; - case 'will_present_notification': + case NotificationType.WillPresent: result = result || (this.show_in_foreground ? WillPresentNotificationResult.All : WillPresentNotificationResult.None); if(!Object.values(WillPresentNotificationResult).includes(result)){ throw new Error(`Invalid WillPresentNotificationResult, make sure you use import {WillPresentNotificationResult} from 'react-native-fcm' to avoid typo`); diff --git a/ios/RNFIRMesssaging.m b/ios/RNFIRMesssaging.m index 6e9ecb20aa288f58910c1bc2d1d1d8b288fd6aef..cf5b9d2bf80b74ab475a6fab86b424a394075c9e 100644 --- a/ios/RNFIRMesssaging.m +++ b/ios/RNFIRMesssaging.m @@ -144,21 +144,21 @@ RCT_EXPORT_MODULE() + (void)didReceiveRemoteNotification:(nonnull NSDictionary *)userInfo fetchCompletionHandler:(RCTRemoteNotificationCallback)completionHandler { NSMutableDictionary* data = [[NSMutableDictionary alloc] initWithDictionary: userInfo]; - [data setValue:@"remote_notification" forKey:@"notification_event_type"]; + [data setValue:@"remote_notification" forKey:@"_notificationType"]; [data setValue:@(RCTSharedApplication().applicationState == UIApplicationStateInactive) forKey:@"opened_from_tray"]; [[NSNotificationCenter defaultCenter] postNotificationName:FCMNotificationReceived object:self userInfo:@{@"data": data, @"completionHandler": completionHandler}]; } + (void)didReceiveLocalNotification:(UILocalNotification *)notification { NSMutableDictionary* data = [[NSMutableDictionary alloc] initWithDictionary: notification.userInfo]; - [data setValue:@"local_notification" forKey:@"notification_event_type"]; + [data setValue:@"local_notification" forKey:@"_notificationType"]; [[NSNotificationCenter defaultCenter] postNotificationName:FCMNotificationReceived object:self userInfo:data]; } + (void)didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(RCTNotificationResponseCallback)completionHandler { NSMutableDictionary* data = [[NSMutableDictionary alloc] initWithDictionary: response.notification.request.content.userInfo]; - [data setValue:@"notification_response" forKey:@"notification_event_type"]; + [data setValue:@"notification_response" forKey:@"_notificationType"]; [data setValue:@YES forKey:@"opened_from_tray"]; [[NSNotificationCenter defaultCenter] postNotificationName:FCMNotificationReceived object:self userInfo:@{@"data": data, @"completionHandler": completionHandler}]; } @@ -166,7 +166,7 @@ RCT_EXPORT_MODULE() + (void)willPresentNotification:(UNNotification *)notification withCompletionHandler:(RCTWillPresentNotificationCallback)completionHandler { NSMutableDictionary* data = [[NSMutableDictionary alloc] initWithDictionary: notification.request.content.userInfo]; - [data setValue:@"will_present_notification" forKey:@"notification_event_type"]; + [data setValue:@"will_present_notification" forKey:@"_notificationType"]; [[NSNotificationCenter defaultCenter] postNotificationName:FCMNotificationReceived object:self userInfo:@{@"data": data, @"completionHandler": completionHandler}]; }