Skip to content

Commit

Permalink
fix(messaging, ios): foreground notification appears twice on iOS 18 (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
russellwheatley authored Nov 7, 2024
1 parent 7e8a1b2 commit ae0197f
Showing 1 changed file with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ @implementation FLTFirebaseMessagingPlugin {

NSString *_initialNotificationID;
NSString *_notificationOpenedAppID;
NSString *_foregroundUniqueIdentifier;

#ifdef __FF_NOTIFICATIONS_SUPPORTED_PLATFORM
API_AVAILABLE(ios(10), macosx(10.14))
Expand Down Expand Up @@ -314,10 +315,17 @@ - (void)userNotificationCenter:(UNUserNotificationCenter *)center
(void (^)(UNNotificationPresentationOptions options))completionHandler
API_AVAILABLE(macos(10.14), ios(10.0)) {
// We only want to handle FCM notifications.
if (notification.request.content.userInfo[@"gcm.message_id"]) {

// FIX - bug on iOS 18 which results in duplicate foreground notifications posted
// 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;

if (notification.request.content.userInfo[@"gcm.message_id"] &&
![notificationIdentifier isEqualToString:_foregroundUniqueIdentifier]) {
NSDictionary *notificationDict =
[FLTFirebaseMessagingPlugin NSDictionaryFromUNNotification:notification];

[_channel invokeMethod:@"Messaging#onMessage" arguments:notificationDict];
}

Expand All @@ -344,6 +352,7 @@ - (void)userNotificationCenter:(UNUserNotificationCenter *)center
}
completionHandler(presentationOptions);
}
_foregroundUniqueIdentifier = notificationIdentifier;
}

// Called when a user interacts with a notification.
Expand Down

0 comments on commit ae0197f

Please sign in to comment.