Explain it simply
Push Notifications Basics, in plain language
The high-level push notification workflow: (1) the app requests permission, (2) it obtains a unique device 'push token', (3) that push token is sent to and stored on a backend server, (4) when some event happens (a message arrives, an order is confirmed), the backend uses the push token to send a notification through a push service like Expo/FCM/APNs. It's important to distinguish local notifications (scheduled by the device itself) from remote/push notifications (triggered by the server).
Problem → Why → Solution
The problem — why this concept matters
Thinking there's no need to store the push token in a backend database — sending remote push requires the backend to know the token
A common mistake
Confusing local vs. push notifications and overcomplicating the backend architecture design
Core concept — understand how it works
Build Push Notifications Basics as a lifecycle-aware flow covering permission, loading, empty, offline, timeout, cancellation, retry, foreground/background transitions, and stale data. Clean up subscriptions, timers, and requests.
- JavaScript state
- native component and layout
- Android or iOS UI
Explain the React and native-platform behavior of Push Notifications Basics
Core syntax or pattern
import * as Notifications from 'expo-notifications';
async function registerForPushNotifications() {
const { status } = await Notifications.requestPermissionsAsync();
if (status !== 'granted') return null;
const tokenData = await Notifications.getExpoPushTokenAsync();
return tokenData.data; // send this to your backend to store
}
// Local notification example (no backend needed)
await Notifications.scheduleNotificationAsync({
content: { title: 'Reminder', body: 'Practice React Native today!' },
trigger: { seconds: 60 },
});Build Push Notifications Basics as a lifecycle-aware flow covering permission, loading, empty, offline, timeout, cancellation, retry, foreground/background transitions, and stale data. Clean up subscriptions, timers, and requests.
Read the code step by step
- JavaScript state
import * as Notifications from 'expo-notifications';The high-level push notification workflow: (1) the app requests permission, (2) it obtains a unique device 'push token', (3) that push token is sent to and stored on a backend server, (4) when some event happens (a message arrives, an order is confirmed), the backend uses the push token to send a notification through a push service like Expo/FCM/APNs. It's important to distinguish local notifications (scheduled by the device itself) from remote/push notifications (triggered by the server).
- native component and layout
}Build Push Notifications Basics as a lifecycle-aware flow covering permission, loading, empty, offline, timeout, cancellation, retry, foreground/background transitions, and stale data. Clean up subscriptions, timers, and requests.
- Android or iOS UI
});Test an original Push Notifications Basics example on Android and iOS with small and large screens, font scaling, dark mode, keyboard and screen reader use, slow/offline networking, denied permissions, and background/foreground transitions. Use DevTools, tests, and a release build where relevant.
- JavaScript state
- native component and layout
- Android or iOS UI
Success
Explain the React and native-platform behavior of Push Notifications Basics
Failure
Thinking there's no need to store the push token in a backend database — sending remote push requires the backend to know the token
Let's think about it this way for a second
The high-level push notification workflow: (1) the app requests permission, (2) it obtains a unique device 'push token', (3) that push token is sent to and stored on a backend server, (4) when some event happens (a message arrives, an order is confirmed), the backend uses the push token to send a notification through a push service like Expo/FCM/APNs. It's important to distinguish local notifications (scheduled by the device itself) from remote/push notifications (triggered by the server).
Let's connect this to a real-world scenario
Install expo-notifications and call Notifications.requestPermissionsAsync() — a permission dialog appears, and once granted, Notifications.getExpoPushTokenAsync() gives you a unique token — this token needs to be stored in a backend database, tied to the user record. Local notifications (e.g. reminders) don't need a backend at all — you can schedule them right on the device with Notifications.scheduleNotificationAsync().
Code Example
import * as Notifications from 'expo-notifications';
async function registerForPushNotifications() {
const { status } = await Notifications.requestPermissionsAsync();
if (status !== 'granted') return null;
const tokenData = await Notifications.getExpoPushTokenAsync();
return tokenData.data; // send this to your backend to store
}
// Local notification example (no backend needed)
await Notifications.scheduleNotificationAsync({
content: { title: 'Reminder', body: 'Practice React Native today!' },
trigger: { seconds: 60 },
});Once permission is granted, you get a push token string, and a local notification triggers after 60 seconds.Try it in 5 minutes
Install expo-notifications and schedule a local notification (scheduleNotificationAsync) yourself (on Expo Go).
A quick word of caution
If you request push notification permission the moment the app opens, users tend to deny it more often — requesting it contextually, at the moment the feature is actually used (e.g. the first time the chat feature is used), gets a better accept rate.
Real-world usage
How to apply it in a real project
Test an original Push Notifications Basics example on Android and iOS with small and large screens, font scaling, dark mode, keyboard and screen reader use, slow/offline networking, denied permissions, and background/foreground transitions. Use DevTools, tests, and a release build where relevant.
Mini challenge
Build it yourself
Test an original Push Notifications Basics example on Android and iOS with small and large screens, font scaling, dark mode, keyboard and screen reader use, slow/offline networking, denied permissions, and background/foreground transitions. Use DevTools, tests, and a release build where relevant.
- Rebuild the example without copying it
- Test a normal input and an edge case
- Predict the compiler or output result before running it
import * as Notifications from 'expo-notifications';
async function registerForPushNotifications() {
const { status } = await Notifications.requestPermissionsAsync();
if (status !== 'granted') return null;
const tokenData = await Notifications.getExpoPushTokenAsync();
return tokenData.data; // send this to your backend to store
}
// Local notification example (no backend needed)
await Notifications.scheduleNotificationAsync({
content: { title: 'Reminder', body: 'Practice React Native today!' },
trigger: { seconds: 60 },
});Expected: Explain the React and native-platform behavior of Push Notifications Basics
Show hint
Test an original Push Notifications Basics example on Android and iOS with small and large screens, font scaling, dark mode, keyboard and screen reader use, slow/offline networking, denied permissions, and background/foreground transitions. Use DevTools, tests, and a release build where relevant.
Quick quiz 1 / 3
Quick quiz 2 / 3
Quick quiz 3 / 3
What to remember
- JavaScript state → native component and layout → Android or iOS UI
- Build Push Notifications Basics as a lifecycle-aware flow covering permission, loading, empty, offline, timeout, cancellation, retry, foreground/background transitions, and stale data. Clean up subscriptions, timers, and requests.
- Thinking there's no need to store the push token in a backend database — sending remote push requires the backend to know the token
- Test an original Push Notifications Basics example on Android and iOS with small and large screens, font scaling, dark mode, keyboard and screen reader use, slow/offline networking, denied permissions, and background/foreground transitions. Use DevTools, tests, and a release build where relevant.
React Native Documentation — React Native