Push Notifications
Notifications pull users back into your app — Expo makes both local reminders and remote push approachable.
What you will learn
- Tell local and remote (push) notifications apart
- Ask permission and get a push token
- Schedule a local notification
Two kinds of notification
A notification is the banner that appears on the lock screen or at the top of the phone, even when your app is closed. There are two kinds, and it helps to keep them straight:
- Local notification — your app schedules it on the device itself (e.g. "remind me in 1 hour"). No server needed.
- Remote / push notification — a server sends it to the phone over the internet (e.g. "you have a new message"). This is what most people mean by "push".
Expo wraps both in one module, expo-notifications, and runs a free service that delivers remote pushes to Android and iOS without you wiring up each platform’s system separately.
Install it (one-time):
npx expo install expo-notificationsNote: Output: (Adds the notifications module. Nothing on screen yet.)
Step 1 — Ask permission and get a push token
Like the camera, notifications need permission first. For remote push you also need this phone’s push token — a unique address the server uses to reach this exact device. You ask for both together:
import * as Notifications from 'expo-notifications';
async function registerForPush() {
const { status } = await Notifications.requestPermissionsAsync();
if (status !== 'granted') {
console.log('Notifications not allowed');
return null;
}
const token = (await Notifications.getExpoPushTokenAsync()).data;
console.log('Push token:', token);
return token; // send this to your server
}Note: Output (when allowed):
Push token: ExponentPushToken[xxxxxxxxxxxxxxxxxxxxxx]
That token is the device’s address. You send it to your server, which later asks Expo’s push service to deliver a notification to exactly this phone. If the user denies permission, you log the message and return null instead.
Step 2 — Schedule a local notification
A local notification is the simplest to try because it needs no server — you schedule it right on the device. Here we fire one 5 seconds from now:
await Notifications.scheduleNotificationAsync({
content: {
title: 'Time to study! 📚',
body: 'Open Code Kaksha and finish today’s lesson.',
},
trigger: { seconds: 5 },
});Note: Output:
After 5 seconds a banner appears:
Time to study! 📚
Open Code Kaksha and finish today’s lesson.
content is what the user sees; trigger is when it fires (here { seconds: 5 }; you can also use a specific date or a daily repeat).
How a remote push reaches the phone, step by step
Remote push has more moving parts. Here is the whole journey, in order, so the pieces make sense:
- On first launch the app calls
requestPermissionsAsync(); the user taps Allow. - The app gets its push token with
getExpoPushTokenAsync()— this device’s unique address. - The app sends that token to your server, which stores it next to the user’s account.
- Later, something happens worth notifying about (a new message). Your server asks Expo’s push service to deliver a notification to that token.
- Expo hands the notification to Apple’s or Google’s system, which shows the banner on the phone — even if your app is closed.
- When the user taps the banner, your app opens (and with deep linking from the earlier lesson, can jump straight to the relevant screen).
Tip: Test local notifications first — they need no backend and prove your permission and content code work. Add remote push once a server is ready to store tokens and send messages. Tools like OneSignal can manage the sending side for you.
Watch out: Remote push does not work in the Expo Go sandbox for iOS and is unreliable on emulators — test it on a real device with a development or production build. Local notifications, however, are fine to try in Expo Go.
Q. What is the push token used for?
✍️ Practice
- Schedule a local notification that fires after 10 seconds with your own title and body.
- Write a
registerForPushfunction that requests permission and logs the push token.
🏠 Homework
- Add a "Remind me" button that schedules a local notification, and (in words) describe the steps to turn it into a server-sent push.