Push notifications not working in production with iOS

I followed this guide: https://docs.expo.io/versions/latest/guides/push-notifications/

Everything works in development through the expo app, but after I publish notifications don’t reach the main app. I’m testing on iOS. Does the app need a new build uploaded like android? I’m sending the push notifications from the backend using the expo node module. I tried deleting the push notification token and having it fetch a new one for that account from the production app. What’s weird is even with both the ‘inside expo’ version and the stand alone app in the store, when they point at the same back end for some reason the notifications only show of for the one running from inside the expo app and not my stand alone production app.

2 Likes

Hey @nickjuntilla,

Can you try using the Push Notif tool to see if they are successfully delivered to your Standalone app?

Cheers,

Adam

1 Like

Nope. Does not work. The token is retrieved fine in the production app, but no notifications are received with tokens pulled in production. This is an example of one that seems to send nowhere: ExponentPushToken[WEKAh7OXQjQOfVazIEHRi2]

Any word on this? Are push notifications still supported with expo? What can we do?

Would uploading FCM credentials cause expo to not send iOS notifications anymore? I did this step here without needing to. Is there any way to undo it? Would uploading an android push key be causing a problem? https://docs.expo.io/versions/v26.0.0/guides/using-fcm/

Hey @nickjuntilla,

Uploading FCM credentials would not affect iOS push notfis. Push notifs are certainly still supported and I’m not seeing any other reports of users having issues with notif delivery at the moment. Would you be able to share the affected build that isn’t receiving notifications as well as a snippet of the relevant code regarding notifs in the app?

That’s good to hear. I’m really hoping to not have to eject. That would probably add a few weeks on to our schedule. Here is the code we’re using:

Client side:

export const registerForPushNotifications = async () => {
  // Check for existing permissions
  const { status: existingStatus } = await Permissions.getAsync(Permissions.NOTIFICATIONS);
  let finalStatus = existingStatus;

  // If no existing permission, ask for permission:
  // Only ask if permissions have not already been determined, because
  // iOS won't necessarily prompt the user a second time.
  if (existingStatus !== 'granted') {
    // Android remote notification permissions are granted during the app
    // install, so this will only ask on iOS
    const { status } = await Permissions.askAsync(Permissions.NOTIFICATIONS);
    finalStatus = status;
  }

  // Stop here if the user did not grant permissions
  if (finalStatus !== 'granted') {
    return false;
  }

  // Get the token that uniquely identifies this device
  const token = await Notifications.getExpoPushTokenAsync();

  // Save the setting on the user object
  api.updateUser({
    expoPushToken: token,
    isPushNotificationsEnabled: true,
  });

  return true;
};

The updateUser simply saves the push notification string in the firebase database. As stated above it looks like this ‘ExponentPushToken[WEKAh7OXQjQOfVazIEHRi2]’

I’ve checked the settings on the app and all notifications are enabled after that client code is run.

The server side code then looks like this. These are the relevant lines. It’s node on firebase functions, but there are no connection problems:

const { Expo } = require('expo-server-sdk');
let expo = new Expo();

...
var pMessages = [];
const pushToken = userData.expoPushToken; // coming from firebase 'ExponentPushToken[WEKAh7OXQjQOfVazIEHRi2]'
pMessages.push({
                to: pushToken,
                sound: 'default',
                title: 'You have received a new message',
                body: 'Open chat to view',
                data: {type:'message',from: userName},
                badge: 1
              })
expo.sendPushNotificationsAsync(pMessages);

I’ve also tried sending push manually and getting a receipt. The receipt looks like this:

{"data":{"ca14c5a2-908c-4fd7-9806-47cf81874888":{"status":"error","message":"The Apple Push Notification service unexpectedly dropped the connection. Retry sending the notification later.","details":{"sentAt":1549139249},"__debug":{"internalError":"stream ended unexpectedly"}}}}

This is also an issue on the expo forum by another user here: https://github.com/expo/expo/issues/2185

But I did not start that issue so I’d like to try and solve it here as well. Expo manages my keys and I don’t want to do build:ios --clear if it’s going to delete my key. Also I don’t want to jump to submitting a new build to Apple unless absolutely necessary as the approval process for a new release takes several days and that’s a long time to wait for a guess. Any ideas?

*Also wanted to remind that all of this works on expo container app, but not stand alone or testflight so I can try something there. Also I’ve retrieved a new expoPushToken in the standalone so I’m not using the same push token as inside the container app.

*Also would the section of building standalone apps called “Switch to Push Notification Key on iOS” help any? What does --clear-push-cert do?

Hey Nick,

Can you try switching to using a PN key with expo build:ios --clear-push-cert to see if that fixes anything? It should be as simple as running that command and it’s the preferred method moving forward.

1 Like

I ended deleting my provisioning profile and having expo generate a new one using
expo build:ios --clear-credentials
Documented here: https://github.com/expo/expo/issues/2185#issuecomment-460875549

I’m happy that worked, but I have no idea why? Do you know why that would work? Does build:ios --clear-push-cert do the same thing for future notice? I’d really like to understand this better. Thank you!

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