The short version
- Install the library and add the config plugin
- Set up credentials for both platforms
- Make a development build
- Ask for permission and get the Expo push token
- Send from your server
- Check the push receipts
- Handle the tap
What you need before any code
The code is the short part. Most of the time goes into accounts and credentials, so collect these first.
| You need | Where it comes from | Good to know |
|---|---|---|
| A development build | eas build with a development profile | Expo Go cannot receive push from SDK 53. |
| Paid Apple Developer account | developer.apple.com | Needed to generate the iOS push key. EAS creates the key for you. |
| Firebase project | Firebase Console | Android push goes through Firebase Cloud Messaging (FCM V1). |
| google-services.json | Firebase Console, project settings | Lives in your project. Holds public identifiers, so it can be committed. |
| Service account key (JSON) | Firebase Console, Service accounts, Generate new private key | Private. Upload it with eas credentials and keep it out of git. |
| Something to test on | A phone, an Android Emulator with Google Play services, or an iOS Simulator on Xcode 14+ | An emulator image without Google Play services will not work. |
The two Android files are easy to mix up. google-services.json identifies your app to Firebase and ships inside the build. The service account key lets Expo send on your behalf and never leaves your Expo account. The Expo docs cover both in Add Android FCM V1 credentials.
Local or remote: check which one you need
A local notification is scheduled by the app on the device itself: a daily reminder, a timer that ends, a habit nudge. It needs no server, no credentials, and it works in Expo Go. A push notification, also called a remote notification, is sent from a server because something happened elsewhere: a new message, an order update.
If every notification in your app can be planned ahead on the device, use local notifications and skip the rest of this guide. If a server decides when to notify, read on.
Step 1: Install the library and add the plugin
npx expo install expo-notifications expo-constants
expo-notifications asks for permission and returns the token. expo-constants reads your project ID from the app config. Then add the plugin, and the path to google-services.json for Android:
{
"expo": {
"plugins": ["expo-notifications"],
"android": {
"googleServicesFile": "./google-services.json"
}
}
}The plugin is why you never edit native files. It also takes options for the Android notification icon and colour, listed in the expo-notifications reference. The Android icon must be all white on a transparent background, or it shows as a grey square.
Step 2: Set up credentials and make a development build
Android. In the Firebase Console, open Settings, then Service accounts, and generate a new private key. Run eas credentials, choose Android, then Google Service Account, and upload that JSON file as the key for push notifications (FCM V1). Download google-services.json from the same Firebase project and put it at the path you set in Step 1.
iOS. Register your test device, then start the build. The first time, the EAS CLI asks whether to set up push notifications and whether to generate a new Apple Push Notifications service key. Answer yes to both.
# First build asks to set up push for iOS. Answer yes to both prompts. eas build --profile development --platform all # Then run the dev server and open the development build. npx expo start
From here on you open the development build, not Expo Go. The full walkthrough with screenshots is in the Expo push notifications setup guide, and the difference between the two apps is in our Expo Go vs development build post.
Step 3: Ask for permission and get the token
import { Platform } from 'react-native';
import * as Notifications from 'expo-notifications';
import Constants from 'expo-constants';
// Decides what happens when a notification arrives while the app is open.
Notifications.setNotificationHandler({
handleNotification: async () => ({
shouldPlaySound: true,
shouldSetBadge: true,
shouldShowBanner: true,
shouldShowList: true,
}),
});
export async function registerForPushNotifications() {
// Android 13+: the permission prompt only appears once a channel exists.
if (Platform.OS === 'android') {
await Notifications.setNotificationChannelAsync('default', {
name: 'default',
importance: Notifications.AndroidImportance.MAX,
});
}
const { status: existing } = await Notifications.getPermissionsAsync();
let status = existing;
if (existing !== 'granted') {
status = (await Notifications.requestPermissionsAsync()).status;
}
if (status !== 'granted') return null;
const projectId =
Constants?.expoConfig?.extra?.eas?.projectId ?? Constants?.easConfig?.projectId;
if (!projectId) throw new Error('Project ID not found');
const token = (await Notifications.getExpoPushTokenAsync({ projectId })).data;
return token; // "ExponentPushToken[...]". Save it on your server.
}Three details in this code are easy to miss:
- The Android channel comes first. On Android 13 and later, the permission prompt does not appear until at least one channel exists, and the channel must be created before you ask for a token.
- Pass the project ID yourself. A development build sets it automatically, but Expo recommends reading it from the app config, so the token stays tied to the project if the account is renamed or the project is transferred.
- Set the handler, or nothing shows while the app is open. When your app is on screen, it decides whether a notification appears.
setNotificationHandleris where you say yes.
Call the function after the user has done something that makes a notification useful, such as joining a chat or placing an order, and save the returned token on your server against that user. One user can have several tokens, one per device.
To confirm the build works before you write any server code, paste the token into the Expo push notifications tool and send yourself a test.
Step 4: Send from your server
Sending is one HTTPS request to Expo. Expo passes the message to FCM for Android and APNs for iOS. This works from a terminal:
curl -H "Content-Type: application/json" \
-X POST "https://exp.host/--/api/v2/push/send" \
-d '{
"to": "ExponentPushToken[xxxxxxxxxxxxxxxxxxxxxx]",
"title": "New message",
"body": "Alex sent you a message.",
"data": { "url": "/chat/42" }
}'On a real server, use one of the SDKs. Expo maintains the Node one, expo-server-sdk, which splits large batches, compresses requests, and throttles for you:
import { Expo } from 'expo-server-sdk';
const expo = new Expo();
export async function sendPush(tokens, title, body, data) {
const messages = tokens
.filter((token) => Expo.isExpoPushToken(token))
.map((to) => ({ to, sound: 'default', title, body, data }));
const tickets = [];
// At most 100 messages per request. The SDK splits them for you.
for (const chunk of expo.chunkPushNotifications(messages)) {
tickets.push(...(await expo.sendPushNotificationsAsync(chunk)));
}
return tickets; // store each ticket id, you need it for the receipt
}The limits to design around, from the Expo docs:
- At most 100 messages in one request, all for the same project.
- At most 600 notifications per second per project.
- The whole payload for one notification must be 4096 bytes or less.
- The service is free, and it has no uptime guarantee, so retry on network errors, 429, and 5xx.
By default anyone holding a push token can send to it. If that worries you, turn on enhanced push security in your Expo account and send an access token with each request. The message fields, including priority, channelId, badge, and ttl, are listed in Send notifications with the Expo Push Service.
Step 5: Check the receipts
This step is easy to skip, and it is the only way to learn that a notification failed. A send goes through two stages, and each one answers separately:
- Push ticket. Returned straight away. A status of
okmeans Expo received the message, not that the user did. - Push receipt. Available after Expo has handed the message to Apple or Google. It tells you whether they accepted it.
Expo recommends fetching receipts 15 minutes after sending. They are deleted after 24 hours, so a job that runs once a day can miss them.
export async function checkReceipts(ticketIds) {
for (const chunk of expo.chunkPushNotificationReceiptIds(ticketIds)) {
const receipts = await expo.getPushNotificationReceiptsAsync(chunk);
for (const [id, receipt] of Object.entries(receipts)) {
if (receipt.status === 'ok') continue;
if (receipt.details?.error === 'DeviceNotRegistered') {
// The app was uninstalled or permission was revoked.
// Delete the token that belongs to this ticket id.
}
console.error(id, receipt.message, receipt.details);
}
}
}The errors worth handling in code:
| Error | Where it appears | What to do |
|---|---|---|
DeviceNotRegistered | Ticket or receipt | Stop sending to this token. Delete it from your database. |
MessageTooBig | Receipt | The whole payload must be 4096 bytes or less. Send an ID in data and fetch the rest in the app. |
MessageRateExceeded | Receipt | Too many messages to one device. Retry later with a growing delay. |
MismatchSenderId | Receipt | The FCM key and google-services.json belong to different Firebase projects. Use one project for both. |
InvalidCredentials | Receipt | The push credentials are missing or revoked. Run eas credentials and add them again. |
TOO_MANY_REQUESTS | Whole request | You passed 600 notifications per second for the project. Throttle and retry. |
PUSH_TOO_MANY_NOTIFICATIONS | Whole request | More than 100 messages in one request. Split the batch. |
Even a receipt of ok is not proof of delivery. It means Apple or Google took the message. If the phone is off, they hold it and try later.
Step 6: Open the right screen on tap
Put a URL in the notification’s data and route to it when the user taps. The catch is the cold start: if the app was closed, the tap happens before your listener exists, so a listener alone misses it. Read the last response at startup as well. This is the pattern from the Expo docs for Expo Router, placed in the root layout:
import { useEffect } from 'react';
import * as Notifications from 'expo-notifications';
import { Slot, router } from 'expo-router';
function useNotificationObserver() {
useEffect(() => {
function redirect(notification: Notifications.Notification) {
const url = notification.request.content.data?.url;
if (typeof url === 'string') {
router.push(url);
Notifications.clearLastNotificationResponse();
}
}
// The app was closed and a tap opened it.
const response = Notifications.getLastNotificationResponse();
if (response?.notification) redirect(response.notification);
// The app was already running.
const subscription = Notifications.addNotificationResponseReceivedListener((r) => {
redirect(r.notification);
});
return () => subscription.remove();
}, []);
}
export default function Layout() {
useNotificationObserver();
return <Slot />;
}clearLastNotificationResponse stops the same notification from redirecting again the next time the layout mounts. If your screens do not have URLs yet, set that up first with the Expo deep linking walkthrough.
What happens in each app state
The same notification behaves differently depending on where your app is when it arrives. For a normal notification with a title and body:
| App is | Who shows the notification | Your code |
|---|---|---|
| Open, on screen | Your app decides, through setNotificationHandler | addNotificationReceivedListener fires |
| In the background | The system shows it | Nothing runs until the user taps |
| Closed | The system shows it | Nothing runs until the user taps |
Running code in the background without showing anything is a different kind of message, which Expo calls a headless background notification. It needs extra iOS configuration, and neither platform promises to run it: Android can hold it back in Doze mode, and Apple advises sending no more than two or three an hour. Use a normal notification unless you truly need background work. The details are in What you need to know about notifications.
When a notification does not arrive
Work down this list in order. Each line rules out one layer.
- Read the ticket and the receipt. An error there names the cause. Nothing else on this list is worth trying until you have looked.
- Schedule a local notification. If that shows up, your permission and handler code are fine, and the problem is the server or the credentials.
- Works in development, fails in the store build. The store build needs your own credentials. Check that the FCM V1 key and the iOS push key are both on the project.
- Android delivers some and drops others. Send with
priority: "high". Normal priority can wait while the phone sleeps. - Android shows nothing at all. If you set a
channelIdthat the app never created, the notification is not displayed. Also, an app the user force-stopped in Android settings receives nothing until it is opened again. - iOS arrives silently or without a badge. The user can allow notifications but turn off sounds or badges.
getPermissionsAsyncreports both underios.allowsSoundandios.allowsBadge. - iOS error about a missing aps-environment entitlement. No push key is set up for the project. Run a new iOS build and let EAS create one.
Expo keeps a longer list in its push notifications troubleshooting and FAQ.
Where ShipNative fits
ShipNative builds a React Native app from a description and lets you download it as an Expo project. It does not add push notifications to the apps it builds today. To add them, download the project and follow the steps above. The project is a standard Expo app, so nothing here needs changing, and the credentials stay in your own Apple, Firebase, and Expo accounts.
