Mrs. Rini moves card #13 to "Ready for pickup", and Wulan's phone chimes right away: "Order #13 is ready for pickup". The app is closed, yet the message still arrives. That's a push notification: a message from a server that shows up on the phone even while the app is closed. It doesn't travel straight there. Say Wulan lives in a gated estate, and Mrs. Rini can't walk in herself to pass on the news. She leaves it with the estate guard, and the guard only delivers if he knows the house number and the resident has said "yes, bring me messages". That guard is Google's and Apple's push service, the house number is the token, and the "yes" is the notification permission.
The path of one push, from the order board to the phone
| Step | Who | What happens |
|---|---|---|
| 1 | App | asks the user for notification permission |
| 2 | App | asks for a token: this phone's address for push |
| 3 | App to the Laravel server | sends the token, the server stores it per device |
| 4 | Server to Expo Push Service | "send 'Order #13 is ready for pickup' to this token" |
| 5 | Expo to FCM / APNs | Android through FCM (Firebase Cloud Messaging), iOS through APNs (Apple Push Notification service) |
| 6 | Phone | the notification shows; tapped, the app opens Order #13 |
So before anything can be sent, the app needs permission and a token. Without a token, the server doesn't know which phone to reach.
Permission and token in the app
npx expo install expo-notifications expo-constants # SDK 57: expo-notifications 57.0.22
Add "expo-notifications" to plugins in app.json. Its plugin adds the aps-environment entitlement on iOS, and the library brings the POST_NOTIFICATIONS permission for Android.
// src/lib/push.ts
import Constants from 'expo-constants';
import * as Notifications from 'expo-notifications';
import { Platform } from 'react-native';
export async function registerPush(): Promise<string | null> {
if (Platform.OS === 'android') {
// Android 13+: the permission dialog only appears once at least one channel exists
await Notifications.setNotificationChannelAsync('order-status', {
name: 'Order status',
importance: Notifications.AndroidImportance.HIGH,
});
}
let permission = await Notifications.getPermissionsAsync();
if (!permission.granted && permission.canAskAgain) {
permission = await Notifications.requestPermissionsAsync();
}
if (!permission.granted) return null; // denied: the app still works, just without push
const projectId = Constants.expoConfig?.extra?.eas?.projectId ?? Constants.easConfig?.projectId;
const { data } = await Notifications.getExpoPushTokenAsync({ projectId });
return data; // "ExponentPushToken[...]"
}
- A channel is a group of notifications on Android 8 and up, with its own sound and importance. The user can mute "Order status" without muting the rest. Once created, the app can only change its name and description.
- Android 13 and up has the
POST_NOTIFICATIONSpermission, and its dialog only appears once a channel exists. That's why the channel comes first. Android 12 and below never asks. - iOS always asks, and only once (the permission rules from the platform lesson). Ask when Wulan has just placed an order, with a line like "Want a heads-up when your laundry is ready?", not the moment the app opens.
- iOS provisional:
requestPermissionsAsync({ ios: { allowAlert: true, allowBadge: true, allowSound: true, allowProvisional: true } })shows no dialog. Notifications land quietly in Notification Center, and the user decides there. Thestatusstays'undetermined', so checkpermission.ios?.status === Notifications.IosAuthorizationStatus.PROVISIONAL. - Expo token vs native token:
getDevicePushTokenAsync()returns an FCM token (Android) or an APNs token (iOS).getExpoPushTokenAsync()sends that native token to Expo's server and gets backExponentPushToken[...], one shape for both platforms.
The server stores tokens and sends the push
The app sends the token to POST /api/me/push-tokens with {"token":"ExponentPushToken[...]","platform":"android"} and the Bearer login token. The server keeps one row per device: a unique token column, plus user_id and platform. Wulan has a phone and a tablet: two rows. The phone gets used by another account: the same row moves to the new user_id.
When #13 becomes "Ready for pickup", the server posts to https://exp.host/--/api/v2/push/send (up to 100 messages per request):
// on the order board server (Laravel)
$res = Http::acceptJson()->post('https://exp.host/--/api/v2/push/send', [[
'to' => 'ExponentPushToken[xxxxxxxxxxxxxxxxxxxxxx]',
'title' => "Mrs. Rini's Laundry",
'body' => 'Order #13 is ready for pickup',
'data' => ['url' => '/order/13'],
'channelId' => 'order-status',
'sound' => 'default',
]]);
{ "data": [{ "status": "ok", "id": "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX" }] }
- This answer is a push ticket.
"ok"only means Expo received the message, not that it reached the phone. - About 15 minutes later the server calls
POST https://exp.host/--/api/v2/push/getReceiptswith{"ids":["XXXXXXXX-..."]}. The answer is a push receipt per id:{"status":"ok"}, or an error with"details":{"error":"DeviceNotRegistered"}. Receipts are deleted after 24 hours. DeviceNotRegisteredmeans that phone can't receive push anymore (the app was uninstalled, for example). Delete its token row and stop sending. Google and Apple decide when this shows up, so uninstalling and sending right away may not produce it.- Other errors:
MessageTooBig(a payload over 4,096 bytes),MessageRateExceeded, and HTTP 429 or 5xx, which you retry with growing delays. - So that Expo can pass messages to FCM and APNs, the FCM V1 key and the APNs key are uploaded to EAS (
eas credentials). APNs needs a paid Apple Developer account.
Other options for sending a push from the server:
| Way | When to pick it |
|---|---|
| Expo Push Service (this lesson) | the default: one token format and one request for Android and iOS |
Directly to FCM HTTP v1 and APNs from Laravel, with the token from getDevicePushTokenAsync() |
you need full control and every FCM and APNs feature, or you don't want to depend on Expo's servers. More work: two APIs, FCM wants an OAuth 2.0 access token and APNs wants a JWT from a .p8 key |
| A third-party push service | you want a dashboard, scheduled sends and user segments without building them yourself |
According to the Expo docs, expo-notifications doesn't lock you into Expo's service, so the code in the app stays the same; only the token sent to the server differs.
Tapping the notification opens Order #13
data.url holds /order/13, the same address as the src/app/order/[id].tsx screen. In the root layout:
// src/app/_layout.tsx (the push part)
Notifications.setNotificationHandler({
handleNotification: async () => ({
shouldShowBanner: true, shouldShowList: true, shouldPlaySound: true, shouldSetBadge: false,
}),
});
function openFromNotification(n: Notifications.Notification) {
const url = n.request.content.data?.url;
if (typeof url === 'string' && url.startsWith('/order/')) router.push(url); // only addresses we know
}
// inside RootLayout
useEffect(() => {
const last = Notifications.getLastNotificationResponse(); // the app was opened FROM a notification
if (last) openFromNotification(last.notification);
const sub = Notifications.addNotificationResponseReceivedListener((r) => openFromNotification(r.notification));
return () => sub.remove();
}, []);
getLastNotificationResponse()handles an app that was closed and opened by the tap. The listener handles an app still alive in the background.setNotificationHandlerdecides about notifications that arrive while the app is open. In SDK 57 and older, without this handler they don't show at all. Since SDK 58 they show without a handler, and the handler is how you hide them or change how they show.- The
/order/13screen still checks its id with the server. The details are in the deep linking lesson.
Expo Go, development builds and simulators
Guess first: the push code is correct, Wulan opens the app in Expo Go on an Android phone, and getExpoPushTokenAsync() is called. What happens?
Since SDK 53, push in Expo Go on Android has been removed. getExpoPushTokenAsync() in Expo Go on Android throws: expo-notifications: Android Push notifications (remote notifications) functionality provided by expo-notifications was removed from Expo Go with the release of SDK 53. Use a development build instead of Expo Go. On iOS, Expo Go only warns, but still test with a development build so the permission, the channel and the app name are your own. Local notifications (scheduled by the app itself) still work in Expo Go.
Push can be tested on a real phone, an Android emulator with Google Play services, and the iOS Simulator from Xcode 14 on. The Device.isDevice check from older tutorials is no longer needed.
⚠️ Why doesn't the notification show, or opens the wrong screen?
- Asking for permission on Android 13 before a channel exists. The dialog doesn't appear. Call
setNotificationChannelAsyncfirst. - Taking a
"ok"ticket as delivered. Check the receipt about 15 minutes later, and delete tokens that come backDeviceNotRegistered. - One token per account. A token belongs to a device. Store it per device, with a unique
token. - Forgetting
setNotificationHandler. In SDK 57 and older, notifications that arrive while the app is open vanish without a trace. Since SDK 58 they still show. router.push(data.url)unchecked.datacomes from outside the app. Accept only addresses you know.
TL;DR: The "Order #13 is ready for pickup" push needs permission and a token first: Android goes through FCM, iOS through APNs, and Expo Push Service wraps both behind an ExponentPushToken[...] token. On Android create the channel first (order-status), because the Android 13 permission dialog only appears once a channel exists; iOS asks once, or use provisional with no dialog (ios.status PROVISIONAL). The server stores tokens per device, posts to exp.host/--/api/v2/push/send (an "ok" ticket means Expo received it), then reads the receipts about 15 minutes later and deletes DeviceNotRegistered tokens. data: { url: '/order/13' } plus getLastNotificationResponse() and addNotificationResponseReceivedListener open Order #13 when tapped, and setNotificationHandler decides about notifications while the app is open: on SDK 57 it is required for them to show, since SDK 58 they show without it. Android push doesn't work in Expo Go since SDK 53: use a development build.
⚡ Permission and token first
Meaning: Before the server can send a push to Wulan's phone, the app needs notification permission, then a token: that phone's address for push. Without a token, the server doesn't know which phone to reach. Android goes through FCM, iOS through APNs, and Expo Push Service wraps both behind an ExponentPushToken[...] token.
⚡ On Android, the channel first
Write:
await Notifications.setNotificationChannelAsync('order-status', {
name: 'Order status',
importance: Notifications.AndroidImportance.HIGH,
});
Meaning: On Android 13 and up, the permission dialog only appears once at least one channel exists. So the channel is created before requestPermissionsAsync(). iOS asks only once, so ask when Wulan has just placed an order.
⚡ A ticket isn't delivery
Guess first: the server sends a push and Expo answers "status": "ok". Has the notification reached the phone?
Not necessarily. An "ok" ticket only means Expo received the message. About 15 minutes later, the server reads its receipt through getReceipts.
Meaning: A receipt with the DeviceNotRegistered error means that phone can't receive push anymore: delete its token row and stop sending.