Push notifications in a React Native / Flutter app — how does it work?

posée 3 months ago122 vuesen

0

I want to notify users when they get a new message, even when the app is closed. What's the architecture for push notifications?

Diagnostic IA

Généré par IA. Ce n'est pas une réponse — la communauté ci-dessous le confirme ou le corrige. Vérifiez toujours avant de vous y fier.

1 réponse

3
✓
✓ Réponse acceptée

The flow:

1. Device registration: the app asks permission (required on Android 13+ and iOS), then gets a device token from the platform service: FCM (Firebase Cloud Messaging) on Android, APNs on iOS. FCM can front both. 2. Send the token to your backend and store it per user and device. Users have several devices, and tokens change, so update them on each app start. 3. When an event happens (new message), your backend calls FCM/APNs with the token and payload. 4. The OS displays the notification even if your app isn't running.

Libraries: - Expo: expo-notifications plus the Expo push service (one API for both platforms). - React Native bare: @react-native-firebase/messaging. - Flutter: firebase_messaging (plus flutter_local_notifications for foreground display).

Backend tips: remove tokens that return "unregistered", don't put sensitive content in the payload (it shows on the lock screen), and let users choose which notifications they receive.

Connectez-vous pour dire si ça a marché.

answered 3 months ago

Sign in and verify your email to post an answer.