
Push Notifications Aren't a Delivery Guarantee: Designing Around FCM and APNs
- كاتب موثّق
محتويات المقال
The common misconception
What actually happens
A message ID means "accepted", not "delivered"
ttl anywhere from 0 to 2,419,200 seconds (28 days). A ttl of 0 means a message that can't be delivered immediately is discarded. And on Android, if a device hasn't connected to FCM for more than a month, FCM "still accepts the message but immediately discards it."
apns-expiration you set, and it warns that notifications "may also get throttled, saved in storage, and in some cases, not delivered."
The OS decides when your app hears about it
AndroidConfigV2 API, still in preview, makes the split explicit: RemoteNotification for urgent, visible notifications and BackgroundSync for updates whose delivery "can be batched or delayed".
content-available with apns-priority 5) is the tool for silent updates, and Apple's docs say the system "doesn't guarantee their delivery". They advise sending no more than two or three per hour. The system may hold one back; when a newer one arrives, it keeps only the newest, and "if something force quits or kills the app, the system discards the held notification." And when a push does wake the app, the work must be quick: iOS gives it 30 seconds, and FCM's Android docs say the time in onMessageReceived is "only expected to be long enough to immediately render a notification". A backgrounded app can be stopped at any moment, as the article on the app lifecycle and process death explains.
Messages get collapsed, capped and reordered
onDeletedMessages in the Android SDK) that is its cue to do a full sync.
Push as a hint, sync as the truth
// Registered with FirebaseMessaging.onMessage and onBackgroundMessageFuture<void> onPush(RemoteMessage message) async { final id = message.data['appointmentId'] as String; final time = DateTime.parse(message.data['time'] as String); // The push IS the update: miss it and the app stays wrong await db.saveAppointmentTime(id, time);}// The push only says "something changed"Future<void> onPush(RemoteMessage message) => pullChanges();// Also called on app start and on every resumeFuture<void> pullChanges() async { final since = await db.lastSyncToken(); final changes = await api.changesSince(since); // Applying the same page twice changes nothing await db.applyChanges(changes.items, changes.nextToken);}How to apply it in your project
Find pushes that carry state Search your push handlers for payload fields written to storage or app state. Each one is a place where a missed push leaves the app wrong. Give the app a pull path Add an endpoint that returns changes since a token, and call it on app start, on resume, on every push and when the app learns that stored messages were deleted. Pick the message by its job Visible, urgent messages get a notification payload and high priority ( apns-priority10 on iOS). Background refreshes get normal priority or a background notification, a collapse key, and attlthat matches how long they're useful.Stop treating "sent" as "seen" Don't mark a user as informed when the send succeeds. If something must reach them, show it in the app on the next sync as well, or use a channel you can confirm. Test the bad days Put an Android device into Doze, swipe the app away on iOS, disable notifications, and check that the app still ends up showing the right data.
Key takeaways
A message ID from FCM means the message was accepted, not delivered. Doze, priority rules, TTL, collapsing and reordering all sit between your server and your app. On iOS, background pushes are low priority, rate-limited and dropped when the app is force quit. Use the push as a hint and keep the truth on the server, synced on start, resume and push. Make syncing idempotent, so duplicate, late or out-of-order pushes are harmless.
📚 المصادر
Set the lifespan of a message — Firebase Cloud Messaging Set and manage Android message priority — Firebase Cloud Messaging Non-collapsible and collapsible messages — Firebase Cloud Messaging Pushing background updates to your App — Apple Developer Documentation Sending notification requests to APNs — Apple Developer Documentation
التعليقات (0)