Skip to content

Commit

Permalink
fix(messaging, ios): eliminate auth/messaging notification race (#6455)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
mikehardy and Gabriel Lesperance authored Aug 7, 2022
1 parent 85585da commit 7183118
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions packages/messaging/ios/RNFBMessaging/RNFBMessaging+AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,24 @@ - (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
NSDictionary *data = userInfo[@"com.google.firebase.auth"];
if ([data isKindOfClass:[NSString class]]) {
// Deserialize in case the data is a JSON string.
NSData *JSONData = [((NSString *)data) dataUsingEncoding:NSUTF8StringEncoding];
data = [NSJSONSerialization JSONObjectWithData:JSONData options:0 error:NULL];
}
if ([data isKindOfClass:[NSDictionary class]] && data[@"warning"]) {
completionHandler(UIBackgroundFetchResultNoData);
return;
}
#endif

[[NSNotificationCenter defaultCenter]
Expand Down

1 comment on commit 7183118

@vercel
Copy link

@vercel vercel bot commented on 7183118 Aug 7, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.