diff --git a/packages/messaging/ios/RNFBMessaging/RNFBMessaging+AppDelegate.m b/packages/messaging/ios/RNFBMessaging/RNFBMessaging+AppDelegate.m index ec26b7019f..c619659033 100644 --- a/packages/messaging/ios/RNFBMessaging/RNFBMessaging+AppDelegate.m +++ b/packages/messaging/ios/RNFBMessaging/RNFBMessaging+AppDelegate.m @@ -210,10 +210,15 @@ - (void)application:(UIApplication *)application [sharedInstance.conditionBackgroundMessageHandlerSet unlock]; } } else { + // TODO: send an event to track notification has been delivered + // Only sends to react for data-only messages DLog(@"didReceiveRemoteNotification while app was in foreground"); - [[RNFBRCTEventEmitter shared] - sendEventWithName:@"messaging_message_received" - body:[RNFBMessagingSerializer remoteMessageUserInfoToDict:userInfo]]; + 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]]; + } completionHandler(UIBackgroundFetchResultNoData); } } diff --git a/packages/messaging/ios/RNFBMessaging/RNFBMessaging+UNUserNotificationCenter.m b/packages/messaging/ios/RNFBMessaging/RNFBMessaging+UNUserNotificationCenter.m index 51456e029b..5e0b3060cd 100644 --- a/packages/messaging/ios/RNFBMessaging/RNFBMessaging+UNUserNotificationCenter.m +++ b/packages/messaging/ios/RNFBMessaging/RNFBMessaging+UNUserNotificationCenter.m @@ -75,14 +75,14 @@ - (void)userNotificationCenter:(UNUserNotificationCenter *)center if (notification.request.content.userInfo[@"gcm.message_id"]) { NSDictionary *notificationDict = [RNFBMessagingSerializer notificationToDict:notification]; - // 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" + // 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]; - } - // TODO in a later version allow customising completion options in JS code + + // TODO in a later version allow customizing completion options in JS code completionHandler(UNNotificationPresentationOptionNone); }