Skip to content

Commit c78f56e

Browse files
authored
fix(messaging, iOS): scope iOS 18 duplicate notification workaround to iOS 18.0 only (#17932)
* fix(messaging, iOS): scope iOS 18 duplicate notification workaround to iOS 18.0 only * fix(messaging, ios): use message id for iOS 18 duplicate filter
1 parent b89e589 commit c78f56e

1 file changed

Lines changed: 22 additions & 4 deletions

File tree

packages/firebase_messaging/firebase_messaging/ios/firebase_messaging/Sources/firebase_messaging/FLTFirebaseMessagingPlugin.m

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -353,10 +353,20 @@ - (void)userNotificationCenter:(UNUserNotificationCenter *)center
353353
// See this Apple issue: https://forums.developer.apple.com/forums/thread/761597
354354
// when it has been resolved, "_foregroundUniqueIdentifier" can be removed (i.e. the commit for
355355
// this fix)
356-
NSString *notificationIdentifier = notification.request.identifier;
356+
NSDictionary *userInfo = notification.request.content.userInfo;
357+
NSString *messageID = userInfo[@"gcm.message_id"];
357358

358-
if (notification.request.content.userInfo[@"gcm.message_id"] &&
359-
![notificationIdentifier isEqualToString:_foregroundUniqueIdentifier]) {
359+
BOOL shouldCheckForDuplicate = NO;
360+
#if !TARGET_OS_OSX
361+
if (@available(iOS 18.0, *)) {
362+
if (!@available(iOS 18.1, *)) {
363+
// Only iOS 18.0 specifically
364+
shouldCheckForDuplicate = [messageID isEqualToString:_foregroundUniqueIdentifier];
365+
}
366+
}
367+
#endif
368+
369+
if (messageID && !shouldCheckForDuplicate) {
360370
NSDictionary *notificationDict =
361371
[FLTFirebaseMessagingPlugin NSDictionaryFromUNNotification:notification];
362372
[_channel invokeMethod:@"Messaging#onMessage" arguments:notificationDict];
@@ -385,7 +395,15 @@ - (void)userNotificationCenter:(UNUserNotificationCenter *)center
385395
}
386396
completionHandler(presentationOptions);
387397
}
388-
_foregroundUniqueIdentifier = notificationIdentifier;
398+
399+
// Store notification identifier for iOS 18.0 duplicate detection
400+
#if !TARGET_OS_OSX
401+
if (@available(iOS 18.0, *)) {
402+
if (!@available(iOS 18.1, *)) {
403+
_foregroundUniqueIdentifier = messageID;
404+
}
405+
}
406+
#endif
389407
}
390408

391409
// Called when a user interacts with a notification.

0 commit comments

Comments
 (0)