iosiphonefirebase-cloud-messagingcapacitor

(silent) push notifications don't trigger didReceiveRemoteNotification


We need to send a receipt confirmation to our backend for some of our push notifications, which we send using Firebase. In order to achieve this, we send background notifications, then send the message id to our backend and display the notification in application(_:didReceiveRemoteNotification:fetchCompletionHandler:). For some reason this stopped working as didReceiveRemoteNotification never seems to be called. We essentially send the messages we need confirmation for like this:

        final var apnsConfig =
                ApnsConfig.builder()
                        .setAps(Aps.builder().setContentAvailable(true).build())
                        .putAllHeaders(Map.of("apns-push-type", "background", "apns-priority", "5"))
                        .putCustomData("customDataKey", "customDataValue")
                        .build();

        final var multicastMessageBuilder =
                MulticastMessage.builder()
                        .setApnsConfig(apnsConfig)
                        .addAllTokens(
                                fcmEntities.stream()
                                        .map(FcmMessageEntity::getFcmRegistrationToken)
                                        .toList());

        multicastMessageBuilder.putAllData(
                Map.of(
                        "notificationTitle",
                        notificationTitle,
                        "notificationBody",
                        notificationBody));

        final var batchResponse =
                FirebaseMessaging.getInstance(firebaseService.getFirebaseApp())
                        .sendEachForMulticast(multicastMessageBuilder.build());

We have the "Background fetch" and "Remote Notifications" background modes enabled: a screenshot showing the "Background fetch" and "Remote Notifications" background modes enabled

"Regular" (visible) notifications are delivered fine.

We use Capacitor and their PushNotifications Plugin in case that's relevant.

What are we missing/doing wrong?

We tried disabling the FirebaseAppDelegateProxy as some search results suggested, but were unsuccessful.

We also tried adding UNUserNotificationCenterDelegate to our AppDelegate, which led to didReceiveRemoteNotification being called on visible notifications only while the app is in the foreground.


Solution

  • Seems like the problem was us testing on a simulator.

    It works fine on an actual device.