Skip to content

Commit 7183118

Browse files
mikehardyGabriel Lesperance
andauthored
fix(messaging, ios): eliminate auth/messaging notification race (#6455)
* 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 * fix(messaging): messaging crashing if receiving JSON data for firebase notification * lint: yarn lint:ios:fix Co-authored-by: Gabriel Lesperance <[email protected]>
1 parent 85585da commit 7183118

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

packages/messaging/ios/RNFBMessaging/RNFBMessaging+AppDelegate.m

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,24 @@ - (void)application:(UIApplication *)application
123123
completionHandler(UIBackgroundFetchResultNoData);
124124
return;
125125
}
126+
127+
// If the notification is a probe notification, always call the completion
128+
// handler with UIBackgroundFetchResultNoData.
129+
//
130+
// This fixes a race condition between `FIRAuth/didReceiveRemoteNotification` and this
131+
// module causing detox to hang when `FIRAuth/didReceiveRemoteNotification` is called first.
132+
// see
133+
// https://stackoverflow.com/questions/72044950/detox-tests-hang-with-pending-items-on-dispatch-queue/72989494
134+
NSDictionary *data = userInfo[@"com.google.firebase.auth"];
135+
if ([data isKindOfClass:[NSString class]]) {
136+
// Deserialize in case the data is a JSON string.
137+
NSData *JSONData = [((NSString *)data) dataUsingEncoding:NSUTF8StringEncoding];
138+
data = [NSJSONSerialization JSONObjectWithData:JSONData options:0 error:NULL];
139+
}
140+
if ([data isKindOfClass:[NSDictionary class]] && data[@"warning"]) {
141+
completionHandler(UIBackgroundFetchResultNoData);
142+
return;
143+
}
126144
#endif
127145

128146
[[NSNotificationCenter defaultCenter]

0 commit comments

Comments
 (0)