From abb91e4861b769485878a0f165d6ba8a9604de5a Mon Sep 17 00:00:00 2001 From: Russell Wheatley Date: Fri, 13 May 2022 16:24:38 +0100 Subject: [PATCH] fix(firebase_messaging): ensure silent foreground messages for iOS are called via event channel. (#8635) * fix(messaging): silent foreground messages for iOS * fix(messaging): single silent foreground message for iOS --- .../ios/Classes/FLTFirebaseMessagingPlugin.m | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/packages/firebase_messaging/firebase_messaging/ios/Classes/FLTFirebaseMessagingPlugin.m b/packages/firebase_messaging/firebase_messaging/ios/Classes/FLTFirebaseMessagingPlugin.m index d4946e099bc5..5ccf97392a68 100644 --- a/packages/firebase_messaging/firebase_messaging/ios/Classes/FLTFirebaseMessagingPlugin.m +++ b/packages/firebase_messaging/firebase_messaging/ios/Classes/FLTFirebaseMessagingPlugin.m @@ -422,6 +422,7 @@ - (void)application:(NSApplication *)application #endif #if !TARGET_OS_OSX +// Called for silent notifications in the foreground & background - (BOOL)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult result))completionHandler { @@ -431,12 +432,10 @@ - (BOOL)application:(UIApplication *)application return YES; } #endif - + NSDictionary *notificationDict = + [FLTFirebaseMessagingPlugin remoteMessageUserInfoToDict:userInfo]; // Only handle notifications from FCM. if (userInfo[@"gcm.message_id"]) { - NSDictionary *notificationDict = - [FLTFirebaseMessagingPlugin remoteMessageUserInfoToDict:userInfo]; - if ([UIApplication sharedApplication].applicationState == UIApplicationStateBackground) { __block BOOL completed = NO; @@ -485,6 +484,11 @@ - (BOOL)application:(UIApplication *)application } }]; } else { + // If "alert" (i.e. notification) is present, this will be called by the other + // "Messaging#onMessage" channel handler + if (notificationDict[@"aps"] != nil && notificationDict[@"aps"][@"alert"] == nil) { + [_channel invokeMethod:@"Messaging#onMessage" arguments:notificationDict]; + } completionHandler(UIBackgroundFetchResultNoData); }