๐Ÿ””

Push Notifications

๐Ÿ‘จโ€๐Ÿณ Chefโฑ๏ธ 25 minutes

๐Ÿ“‹ Suggested prerequisites

  • โ€ขExpo app
  • โ€ขBackend

What you'll build

A push notification system that sends alerts to your users' phones even when they're not using the app. You'll implement the complete flow: request permissions from the user, get the Expo Push token, save it to your backend, and send personalized notifications from your server. When finished, you'll be able to send notifications with title, message, and extra data that open specific screens of your app when the user taps them.


With Expo Push

npx expo install expo-notifications expo-device

Get token

import * as Notifications from 'expo-notifications'
import * as Device from 'expo-device'

async function registerForPush() {
  if (!Device.isDevice) return

  const { status } = await Notifications.requestPermissionsAsync()
  if (status !== 'granted') return

  const token = await Notifications.getExpoPushTokenAsync()
  // Save token to your backend
  return token.data
}

Send from backend

await fetch('https://exp.host/--/api/v2/push/send', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({
    to: 'ExponentPushToken[xxx]',
    title: 'New message',
    body: 'You have a new message',
    data: { screen: 'Chat' }
  })
})

Next step

โ†’ Webhook Receiver