Unable to get a Expo Push Notifications Token for iOS

  1. SDK Version: 45
  2. Platforms(Android/iOS/web/all): iOS
  3. Managed workflow, EAS Local Build

I have the following code block that used to work before, but doesn’t seem to work correctly anymore…

const getPushNotificationPermissions = async () => {
  try {
    const { status: existingStatus } = await Notifications.getPermissionsAsync();
    let finalStatus = existingStatus;
    if (existingStatus != 'granted') {
      const { status } = await Notifications.requestPermissionsAsync({
        ios: {
          allowAlert: true,
          allowBadge: true,
          allowSound: true,
          allowAnnouncements: true,
        },
      });
      finalStatus = status;
    }
    if (finalStatus != 'granted') {
      Alert.alert('You need to enable permissions in settings to receive push notifications');
      return null;
    }
    // fails here
    return await Notifications.getExpoPushTokenAsync();
  } catch (e) {
    console.error(
      'Unable to get notification access, most likely because we ar running in a simulator',
      e
    );
    return null;
  }
};

I have an EAS build (using eas-local-build-plugin) with the current eas and plugins installed (I didn’t lock the version during the build process so it always does npm -g eas-cli expo-cli eas-cli-local-build-plugin as part of the build to make sure I get the current ones.

I had reuploaded the certificates using eas credentials

My EAS build looks like this on Azure pipelines

  - bash: |
      eas build --platform=${{ parameters.platform }} --profile=${{ parameters.profile }} --non-interactive --local
    env:
      EXPO_TOKEN: $(expoToken)
      EAS_DEBUG: "true"
      EAS_LOCAL_BUILD_WORKINGDIR: $(Agent.TempDirectory)/$(Build.BuildId)
      EAS_LOCAL_BUILD_ARTIFACTS_DIR: $(Build.ArtifactStagingDirectory)

The error I got logged was

received: 400 (body: “{“errors”:[{“code”:“VALIDATION_ERROR”,“message”:“The Expo push notification service is supported only for Expo projects. Ensure you are logged in to your Expo developer account on the computer from which you are loading your project.”,“isTransient”:false}]}”).

This is on a real device from a test flight build.

In eas credentials I see the push key associated

Push Key
Developer Portal ID        XXXXXXXXX
Apple Team                 YYYYYYYYYY
Updated                    26 minutes ago

The eas.json looks like this

{
  "build": {
    "production": {},
    "preview": {
      "android": {
        "buildType": "apk"
      },
      "distribution": "internal"
    },
    "development": {
      "developmentClient": true,
      "distribution": "internal"
    }
  },
  "cli": {
    "version": ">= 0.35.0"
  }
}

Another thing I noticed is that I don’t get any errors on Expo Go

Can you clarify when in the process you’re getting that 400 error? Is that when building, at runtime, when sending a notification, etc.

This depends on where that error happens, but one thing that might help [is passing in the experienceId when calling getExpoPushTokenAsync()](https://The Expo push notification service is supported only for Expo projects.)

2 Likes

This is somewhere early on in application startup. We’re not sending the token to our backends yet, we’re just obtaining the token so that when they login we have it ready to send to link the user to the device token.

But thanks for the information about the experience ID. I didn’t notice that earlier. Going to try it out soon.

 const expoPushToken = await Notifications.getExpoPushTokenAsync({
    experienceId: '@username/example',
  });

However, I do have a stack overflow question on how do we even get the experience ID or application slug at run time? javascript - How do I get the app.json slug value from the app? - Stack Overflow

Debugging further… it seems that my application ID in the Constants

"currentFullName":"@anonymous/XXXX"

I am doing EAS local build but I don’t think that should be the cause because I still had to login and I have my expo token when building.

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