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); }