From 941128b2fce9e22123fbc452798b48e706844f8f Mon Sep 17 00:00:00 2001 From: Gabriel Lesperance Date: Fri, 15 Jul 2022 13:24:19 -0400 Subject: [PATCH] fix(messaging): Fixes a race condition between `FIRAuth/didReceiveRemoteNotification` and this module causing detox to hang when `FIRAuth/didReceiveRemoteNotification` is called first. see https://stackoverflow.com/questions/72044950/detox-tests-hang-with-pending-items-on-dispatch-queue/72989494 --- .../ios/RNFBMessaging/RNFBMessaging+AppDelegate.m | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/packages/messaging/ios/RNFBMessaging/RNFBMessaging+AppDelegate.m b/packages/messaging/ios/RNFBMessaging/RNFBMessaging+AppDelegate.m index ec26b7019f8..743fe416bd7 100644 --- a/packages/messaging/ios/RNFBMessaging/RNFBMessaging+AppDelegate.m +++ b/packages/messaging/ios/RNFBMessaging/RNFBMessaging+AppDelegate.m @@ -123,6 +123,18 @@ - (void)application:(UIApplication *)application completionHandler(UIBackgroundFetchResultNoData); return; } + + // If the notification is a probe notification, always call the completion + // handler with UIBackgroundFetchResultNoData. + // + // This fixes a race condition between `FIRAuth/didReceiveRemoteNotification` and this + // module causing detox to hang when `FIRAuth/didReceiveRemoteNotification` is called first. + // see https://stackoverflow.com/questions/72044950/detox-tests-hang-with-pending-items-on-dispatch-queue/72989494#72989494 + NSDictionary *data = userInfo[@"com.google.firebase.auth"]; + if (data && data[@"warning"]) { + completionHandler(UIBackgroundFetchResultNoData); + return; + } #endif [[NSNotificationCenter defaultCenter]