Skip to content

Commit

Permalink
fix(firebase_messaging): ensure silent foreground messages for iOS ar…
Browse files Browse the repository at this point in the history
…e called via event channel. (#8635)

* fix(messaging): silent foreground messages for iOS

* fix(messaging): single silent foreground message for iOS
  • Loading branch information
russellwheatley committed May 13, 2022
1 parent 49077d6 commit abb91e4
Showing 1 changed file with 8 additions and 4 deletions.
Expand Up @@ -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 {
Expand All @@ -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;

Expand Down Expand Up @@ -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);
}

Expand Down

0 comments on commit abb91e4

Please sign in to comment.