Thuta Learning
React Native
AdvancedMobile DevelopmentIntermediate

Push Notifications Basics

React NativeLesson 2325 min

What you'll walk away with

  • Explain the React and native-platform behavior of Push Notifications Basics
  • Test accessibility, failure, and lifecycle cases
  • Write maintainable, testable, and performant React Native

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.

Mental model
  1. JavaScript state
  2. native component and layout
  3. Android or iOS UI

Explain the React and native-platform behavior of Push Notifications Basics

Core syntax or pattern

javascript
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

  1. JavaScript stateimport * 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).

  2. 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.

  3. 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.

Execution flow
  1. JavaScript state
  2. native component and layout
  3. 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

javascript
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 },
});
You should see
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
javascript
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

What best describes the core idea of Push Notifications Basics?

Quick quiz 2 / 3

Which mistake should you avoid first?

Quick quiz 3 / 3

How should this be applied in a real project?

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

Easy traps

  • Thinking there's no need to store the push token in a backend database — sending remote push requires the backend to know the token
  • Confusing local vs. push notifications and overcomplicating the backend architecture design
  • Assuming one simulator's happy path proves every real-device, release-build, permission, accessibility, offline, and lifecycle path.

Hands-on Exercise

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.

You'll know it worked when: Once permission is granted, you get a push token string, and a local notification triggers after 60 seconds.

Updated on

Progress is saved only in this browser on this device. It isn't synced to other devices.

Report a problem with this lessonOpens your email app with this lesson's address filled in — nothing is sent until you send it.

Push Notifications Basics | Thuta Learning