GuidesMobile apps

Tutorial: sending push notifications with Expo

By the Banzai Labs teamUpdated on 2 min read

Your serverExpo PushAPNs · FCMDevice tokenExponentPushToken[…]One message, routed to Apple or Google
Your server sends to Expo’s service, which forwards to Apple or Google, then to the phone.

1. In the app

import * as Notifications from 'expo-notifications';
import Constants from 'expo-constants';

export async function register() {
  const { status } = await Notifications.requestPermissionsAsync();
  if (status !== 'granted') return null;
  const projectId = Constants.expoConfig?.extra?.eas?.projectId;
  const { data } = await Notifications.getExpoPushTokenAsync({ projectId });
  await fetch('https://api.example.com/push-tokens', { method: 'POST', body: JSON.stringify({ token: data }) });
  return data;
}

2. On the server

await fetch('https://exp.host/--/api/v2/push/send', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({
    to: token,
    title: 'Your order has shipped',
    body: 'Expected delivery on Thursday.',
    data: { url: '/orders/1042' },
  }),
});

The expo-server-sdk server SDK batches the sends and reads the receipts.

3. Receipts

  1. 1The ticketReturned right away: the message is accepted.
  2. 2The receiptChecked later: delivered to Apple or Google, or not.
  3. 3Clean-upA “DeviceNotRegistered” token is deleted.

4. Don’t wear users out

  • A useful, expected notification, not advertising in disguise.
  • Per-type settings in the app (orders, promotions).
  • A deep link that opens the right screen.

To publish the app: EAS, from build to stores.

Frequently asked questions

Do notifications work in the simulator?
Not reliably: test on a real phone, with a development or production build.
Do I need to set up Firebase?
For Android, yes: the Firebase Cloud Messaging credentials are declared in EAS. For iOS, EAS can generate the required Apple key.
When should I ask for permission?
When the notification is obviously useful (“let me know when my order ships”), not on first launch.

Read next

All guides