diff --git a/packages/firebase_messaging/firebase_messaging/ios/firebase_messaging/Sources/firebase_messaging/FLTFirebaseMessagingPlugin.m b/packages/firebase_messaging/firebase_messaging/ios/firebase_messaging/Sources/firebase_messaging/FLTFirebaseMessagingPlugin.m index 8a89462afbe6..3d8c9298a4e9 100644 --- a/packages/firebase_messaging/firebase_messaging/ios/firebase_messaging/Sources/firebase_messaging/FLTFirebaseMessagingPlugin.m +++ b/packages/firebase_messaging/firebase_messaging/ios/firebase_messaging/Sources/firebase_messaging/FLTFirebaseMessagingPlugin.m @@ -353,10 +353,20 @@ - (void)userNotificationCenter:(UNUserNotificationCenter *)center // See this Apple issue: https://forums.developer.apple.com/forums/thread/761597 // when it has been resolved, "_foregroundUniqueIdentifier" can be removed (i.e. the commit for // this fix) - NSString *notificationIdentifier = notification.request.identifier; + NSDictionary *userInfo = notification.request.content.userInfo; + NSString *messageID = userInfo[@"gcm.message_id"]; - if (notification.request.content.userInfo[@"gcm.message_id"] && - ![notificationIdentifier isEqualToString:_foregroundUniqueIdentifier]) { + BOOL shouldCheckForDuplicate = NO; +#if !TARGET_OS_OSX + if (@available(iOS 18.0, *)) { + if (!@available(iOS 18.1, *)) { + // Only iOS 18.0 specifically + shouldCheckForDuplicate = [messageID isEqualToString:_foregroundUniqueIdentifier]; + } + } +#endif + + if (messageID && !shouldCheckForDuplicate) { NSDictionary *notificationDict = [FLTFirebaseMessagingPlugin NSDictionaryFromUNNotification:notification]; [_channel invokeMethod:@"Messaging#onMessage" arguments:notificationDict]; @@ -385,7 +395,15 @@ - (void)userNotificationCenter:(UNUserNotificationCenter *)center } completionHandler(presentationOptions); } - _foregroundUniqueIdentifier = notificationIdentifier; + + // Store notification identifier for iOS 18.0 duplicate detection +#if !TARGET_OS_OSX + if (@available(iOS 18.0, *)) { + if (!@available(iOS 18.1, *)) { + _foregroundUniqueIdentifier = messageID; + } + } +#endif } // Called when a user interacts with a notification.