@@ -34,6 +34,7 @@ @implementation FLTFirebaseMessagingPlugin {
3434
3535 NSString *_initialNotificationID;
3636 NSString *_notificationOpenedAppID;
37+ NSString *_foregroundUniqueIdentifier;
3738
3839#ifdef __FF_NOTIFICATIONS_SUPPORTED_PLATFORM
3940 API_AVAILABLE (ios (10 ), macosx (10.14 ))
@@ -314,10 +315,17 @@ - (void)userNotificationCenter:(UNUserNotificationCenter *)center
314315 (void (^)(UNNotificationPresentationOptions options))completionHandler
315316 API_AVAILABLE(macos(10.14 ), ios(10.0 )) {
316317 // We only want to handle FCM notifications.
317- if (notification.request .content .userInfo [@" gcm.message_id" ]) {
318+
319+ // FIX - bug on iOS 18 which results in duplicate foreground notifications posted
320+ // See this Apple issue: https://forums.developer.apple.com/forums/thread/761597
321+ // when it has been resolved, "_foregroundUniqueIdentifier" can be removed (i.e. the commit for
322+ // this fix)
323+ NSString *notificationIdentifier = notification.request .identifier ;
324+
325+ if (notification.request .content .userInfo [@" gcm.message_id" ] &&
326+ ![notificationIdentifier isEqualToString: _foregroundUniqueIdentifier]) {
318327 NSDictionary *notificationDict =
319328 [FLTFirebaseMessagingPlugin NSDictionaryFromUNNotification: notification];
320-
321329 [_channel invokeMethod: @" Messaging#onMessage" arguments: notificationDict];
322330 }
323331
@@ -344,6 +352,7 @@ - (void)userNotificationCenter:(UNUserNotificationCenter *)center
344352 }
345353 completionHandler (presentationOptions);
346354 }
355+ _foregroundUniqueIdentifier = notificationIdentifier;
347356}
348357
349358// Called when a user interacts with a notification.
0 commit comments