Push Notifications received intermittently


#1

Hey! I have an app that uses Expo Push Notifications. The issue that we have is that the Push Notifications sometimes comes sometimes not (tested in Android and iOs, with apps running in background, foreground, etc).
For sending push notifications we are using https://github.com/expo/expo-server-sdk-node
We are doing like in the documentation:

if (tokenDevices && Array.isArray(tokenDevices) && tokenDevices.length > 0) {
    const messages = tokenDevices.map((token) => {
      if (!Expo.isExpoPushToken(token)) {
        console.error(`Push token ${token} is not a valid Expo push token`);
        return null;
      }
      return {
        to: token,
        sound: 'default',
        body: msg || 'This is a test notification',
        data: data || {},
      };
    });

    const chunks = expo.chunkPushNotifications(messages);

    if (chunks) {
      const chunkPromises = chunks.map(chunk => (
        expo.sendPushNotificationsAsync(chunk)
      ));
      try {
        const results = await Promise.all(chunkPromises);
      } catch (e) {
        FALogger.fatal(e);
      }
    }
  }

And the response we get in results is an array of ids with the status being ok. But like I said, sometimes the push notification doesn’t come to the device.

So implemented an endpoint to validate after sometime if an error occurred when trying to push these notifications, as the expo-server-sdk documentation suggest:

      const receiptIdChunks = expo.chunkPushNotificationReceiptIds(args.ids);
      for (let chunk of receiptIdChunks) {
        try {
          let receipts = await expo.getPushNotificationReceiptsAsync(chunk);
          console.log(receipts);
        } catch (error) {
          console.error(error);
        }
      }

And even after 1 hour, the response I get is that all notifications were sent correctly.

The next ids are actual receipt ids that failed. there is a way to get more feedback on what happened with these ones? on why they didn’t reach the device. (Some of these notifications might went to already invalid tokens, but at least one was valid).

{ '2436d50d-8430-4172-b56f-d72528381584': { status: 'ok' },
  '32ca1c97-e8c9-4ac7-ba1f-005aeaec9f8a': { status: 'ok' },
  '4c5765c5-6c6c-4e72-a09d-58f2d746223b': { status: 'ok' },
  '4f44b7f9-3a7b-4cbb-812f-a135f780e50c': { status: 'ok' },
  '53b4a285-ab25-4431-993b-420dd95e7e26': { status: 'ok' },
  '5ad866bd-a8a2-4d57-bb0d-0b230e57600b': { status: 'ok' },
  '91cf7dff-f577-4b2b-af9a-755467d8d3ee': { status: 'ok' },
  '9642b367-b695-4f6b-b1ef-08a6697cb6b2': { status: 'ok' },
  '98fbc19f-43c4-4c3e-b6f5-beea68e4e33c': { status: 'ok' },
  '9ef9d66f-dcd6-473c-98e2-799306bf3306': { status: 'ok' },
  'e21783b6-6c08-4c5a-a4bf-f90658ce65b7': { status: 'ok' } }

#2

I’m testing a new app at the moment and can concur. I sent two push notifications to my test Android device using the Node SDK, spaced apart by 15 minutes. Both received {status: ‘ok’} but only the second one arrived.

The app is set up to use FCM.


closed #3

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.