🔔

Push Notifications

👨‍🍳 Chef⏱️ 25 minutos

📋 Prerequisitos sugeridos

  • Expo app
  • Backend

Lo que vas a construir

Un sistema de notificaciones push que envia alertas al telefono de tus usuarios incluso cuando no estan usando la app. Implementaras el flujo completo: solicitar permisos al usuario, obtener el token de Expo Push, guardarlo en tu backend y enviar notificaciones personalizadas desde tu servidor. Al terminar, podras enviar notificaciones con titulo, mensaje y datos extra que abren pantallas especificas de tu app cuando el usuario las toca.


Con Expo Push

npx expo install expo-notifications expo-device

Obtener 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()
  // Guardar token en tu backend
  return token.data
}

Enviar desde backend

await fetch('https://exp.host/--/api/v2/push/send', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({
    to: 'ExponentPushToken[xxx]',
    title: 'Nuevo mensaje',
    body: 'Tienes un mensaje nuevo',
    data: { screen: 'Chat' }
  })
})

Próximo paso

Receptor de Webhooks