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

poze 3 months ago119 gadeen

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?

Dyagnostik IA

Se IA ki fè l. Se pa yon repons — kominote a anba a konfime oswa korije l. Toujou verifye anvan ou fye l.

1 Repons

3
✓
✓ Repons yo aksepte

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.

Konekte pou di lòt moun si li te mache.

answered 3 months ago

Sign in and verify your email to post an answer.