We are facing an issue with push notifications on our iOS production application and would appreciate guidance.
Issue Summary
Push notifications were working correctly previously but stopped working around two weeks ago.
We use Firebase Cloud Messaging (FCM) for push notifications, which delivers notifications to our iOS application through APNs.
The issue appears to be related to existing FCM tokens.
Existing FCM Token
We have an FCM token already stored in our production backend database.
When we try to send a notification using this token:
- Our backend sometimes receives the following response:
{
"error": {
"code": 404,
"message": "NotRegistered",
"status": "NOT_FOUND",
"details": [
{
"@type": "type.googleapis.com/google.firebase.fcm.v1.FcmError",
"errorCode": "UNREGISTERED"
}
]
}
}
- In some cases, the API request appears successful, but the notification is still not received on the iPhone.
- We also copied the exact same existing token and tested it directly using Firebase Console → Send test message.
- The notification was not received on the device.
Newly Generated / Retrieved FCM Token
We then generated/retrieved the FCM token again from the same application and tested it directly from Firebase Console.
Using the newly retrieved token:
- The notification was successfully received on the same iPhone.
This means the following behaviour is observed:
Existing FCM Token
↓
Backend may return 404 UNREGISTERED
OR Firebase may accept the send request
↓
Notification not received
But after retrieving the token again:
FCM Token Retrieved Again
↓
Firebase Console Test
↓
Notification received successfully
Client-Side Configuration
We have confirmed the following:
- APNs device token is successfully generated.
- FCM registration token is successfully generated.
- Notification permission is granted.
- The application is connected to the correct Firebase project.
FirebaseAppDelegateProxyEnabledis set toNO.- Since Firebase method swizzling is disabled, we manually assign the APNs token to Firebase Messaging.
Our APNs registration code is:
func application(
_ application: UIApplication,
didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data
) {
print("*** APNS Device Token: ", deviceToken)
Messaging.messaging().apnsToken = deviceToken
Messaging.messaging().subscribe(toTopic: "testing_new_events") { error in
if let error = error {
print("*** Failed to subscribe: \(error.localizedDescription)")
} else {
print("*** Subscribed to topic successfully")
}
}
}
Main Question About the 404 UNREGISTERED Response
One part of this behaviour is particularly confusing to us.
If Firebase returns:
404
UNREGISTERED
NotRegistered
for a particular FCM token, we would expect that token to be invalid and that the application should receive or generate a completely new FCM registration token.
However, when we retrieve the FCM token again from the application, Firebase may return the same token value again.
Our question is:
If Firebase considers an FCM token unregistered and returns 404 UNREGISTERED when sending a notification, why can Messaging.messaging().token() or the token callback still return the same token again instead of generating a new token?
For example:
Token A stored in backend
↓
Backend sends notification
↓
FCM returns 404 UNREGISTERED
↓
App retrieves FCM token again
↓
Firebase returns Token A again
We would like to understand whether this is expected behaviour.
Specifically:
- Does
UNREGISTEREDalways mean that the locally cached FCM token should immediately be replaced with a new token? - If not, why can the same FCM token still be returned to the application after Firebase returns
UNREGISTEREDfor it? - Is there a delay between Firebase invalidating a registration for sending and the client generating a replacement token?
- Is there a recommended way to force Firebase Messaging to refresh or re-register an FCM token after receiving
UNREGISTERED? - Could the token be cached locally even though its server-side registration is no longer valid?
Additional Questions
We would also appreciate guidance on the following:
-
Is it possible for an existing FCM token to become stale or no longer usable for notification delivery without immediately returning an
UNREGISTEREDerror for every send attempt? -
Can Firebase accept a message for an existing token and return a successful response, while the notification is never delivered to the device?
-
On iOS, could the relationship between an existing FCM token and its APNs token become invalid or stale, while the application still returns the same FCM token?
-
Is there any APNs-side reason why an old FCM token would stop receiving notifications while a newly generated/retrieved token on the same device receives notifications successfully?
-
What is the recommended client-side and backend-side handling after receiving a
404 UNREGISTEREDresponse? Should we immediately remove the token from our database and wait for the application to register a new token?
Our main concern is understanding why an FCM token can receive a 404 UNREGISTERED response during sending, but the application can still return the same token when we attempt to retrieve it again.
Any guidance on whether this behaviour is expected, particularly regarding the interaction between FCM token registration and APNs on iOS, would be greatly appreciated.