New tool for testing Expo push notifications

Some of the questions & issues we’ve seen about push notifications have to do with the payloads sent to the Expo push service. To make it easier to try out different push notification payloads, we’ve made a webpage for testing push notifications, the Expo push notification tool.


Trying the push notification tool:

First, you’ll need an Expo push token for your (real) device. In iOS, you must ask for permission to show notifications:

import { Permissions } from 'expo';

async function requestNotificationsPermissionAsync() {
  const oldPermission = await Permissions.getAsync(Permissions.NOTIFICATIONS);
  if (oldPermission.status === 'granted') {
    return true;
  }

  const newPermission = await Permissions.askAsync(Permissions.NOTIFICATIONS);
  return newPermission.status === 'granted';
}

And then get an Expo push token (requires an internet connection):

import { Notifications } from 'expo';

async function printExpoPushTokenAsync() {
  const hasPermission = await requestNotificationsPermissionAsync();
  if (hasPermission) {
    const pushToken = await Notifications.getExpoPushTokenAsync();
    console.log(`Your device's Expo push token is: ${pushToken}`);
  } else {
    console.log(`Your device does not have permission to show push notifications.`);
  }
}

Once you have an Expo push token, you can enter it into the “Expo push token” field on the tool page. Enter a sample title and message body and send the notification. (On iOS, background your app first. This is because iOS does not display notifications for the foregrounded app.)


You should receive the notification shortly if all goes well. If there is an error delivering your notification to Apple or Google, you will receive an error message in the tool. This is what a notification to the Expo client looks like:

5 Likes

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