diff --git a/packages/messaging/ios/RNFBMessaging/RNFBMessaging+AppDelegate.m b/packages/messaging/ios/RNFBMessaging/RNFBMessaging+AppDelegate.m index f4b04db307..ec26b7019f 100644 --- a/packages/messaging/ios/RNFBMessaging/RNFBMessaging+AppDelegate.m +++ b/packages/messaging/ios/RNFBMessaging/RNFBMessaging+AppDelegate.m @@ -210,16 +210,10 @@ - (void)application:(UIApplication *)application [sharedInstance.conditionBackgroundMessageHandlerSet unlock]; } } else { - // TODO: send an event to track notification has been delivered (possible needs a new event - // handler for `didReceiveRemoteNotification`) Only sends for data-only messages DLog(@"didReceiveRemoteNotification while app was in foreground"); - if (userInfo[@"aps"][@"alert"] == nil) { - DLog(@"didReceiveRemoteNotification send event for data-only message while app was in " - @"foreground"); - [[RNFBRCTEventEmitter shared] - sendEventWithName:@"messaging_message_received" - body:[RNFBMessagingSerializer remoteMessageUserInfoToDict:userInfo]]; - } + [[RNFBRCTEventEmitter shared] + sendEventWithName:@"messaging_message_received" + body:[RNFBMessagingSerializer remoteMessageUserInfoToDict:userInfo]]; completionHandler(UIBackgroundFetchResultNoData); } } diff --git a/packages/messaging/ios/RNFBMessaging/RNFBMessaging+UNUserNotificationCenter.m b/packages/messaging/ios/RNFBMessaging/RNFBMessaging+UNUserNotificationCenter.m index 394b9874c0..51456e029b 100644 --- a/packages/messaging/ios/RNFBMessaging/RNFBMessaging+UNUserNotificationCenter.m +++ b/packages/messaging/ios/RNFBMessaging/RNFBMessaging+UNUserNotificationCenter.m @@ -75,13 +75,14 @@ - (void)userNotificationCenter:(UNUserNotificationCenter *)center if (notification.request.content.userInfo[@"gcm.message_id"]) { NSDictionary *notificationDict = [RNFBMessagingSerializer notificationToDict:notification]; - // Always send an event to know there is an incoming message in the foreground - // Client app will have to display the notification as `UNNotificationPresentationOptionNone` is - // always sent to completion handler (see below) - [[RNFBRCTEventEmitter shared] sendEventWithName:@"messaging_message_received" - body:notificationDict]; + // Don't send an event if contentAvailable is true - application:didReceiveRemoteNotification + // will send the event for us, we don't want to duplicate them + if (!notificationDict[@"contentAvailable"]) { + [[RNFBRCTEventEmitter shared] sendEventWithName:@"messaging_message_received" + body:notificationDict]; + } - // TODO in a later version allow customizing completion options in JS code + // TODO in a later version allow customising completion options in JS code completionHandler(UNNotificationPresentationOptionNone); }