Skip to content

Commit

Permalink
fix: onMessage to only trigger for data-only or undelivered messages
Browse files Browse the repository at this point in the history
  • Loading branch information
helenaford authored and mikehardy committed Aug 18, 2021
1 parent af336a3 commit a31643b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
11 changes: 8 additions & 3 deletions packages/messaging/ios/RNFBMessaging/RNFBMessaging+AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -210,10 +210,15 @@ - (void)application:(UIApplication *)application
[sharedInstance.conditionBackgroundMessageHandlerSet unlock];
}
} else {
// TODO: send an event to track notification has been delivered
// Only sends to react for data-only messages
DLog(@"didReceiveRemoteNotification while app was in foreground");
[[RNFBRCTEventEmitter shared]
sendEventWithName:@"messaging_message_received"
body:[RNFBMessagingSerializer remoteMessageUserInfoToDict:userInfo]];
if (userInfo[@"aps"][@"alert"] == nil) {
DLog(@"didReceiveRemoteNotification send event for data-only message while app was in foreground");
[[RNFBRCTEventEmitter shared]
sendEventWithName:@"messaging_message_received"
body:[RNFBMessagingSerializer remoteMessageUserInfoToDict:userInfo]];
}
completionHandler(UIBackgroundFetchResultNoData);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,14 @@ - (void)userNotificationCenter:(UNUserNotificationCenter *)center
if (notification.request.content.userInfo[@"gcm.message_id"]) {
NSDictionary *notificationDict = [RNFBMessagingSerializer notificationToDict:notification];

// Don't send an event if contentAvailable is true - application:didReceiveRemoteNotification
// will send the event for us, we don't want to duplicate them
if (!notificationDict[@"contentAvailable"]) {
[[RNFBRCTEventEmitter shared] sendEventWithName:@"messaging_message_received"
// Always send an event to know there is an incoming message in the foreground
// Client app will have to display the notification as `UNNotificationPresentationOptionNone` is always sent
// to completion handler (see below)
[[RNFBRCTEventEmitter shared] sendEventWithName:@"messaging_message_received"
body:notificationDict];
}

// TODO in a later version allow customising completion options in JS code

// TODO in a later version allow customizing completion options in JS code
completionHandler(UNNotificationPresentationOptionNone);
}

Expand Down

0 comments on commit a31643b

Please sign in to comment.