Search code examples
iosfirebasereact-nativefirebase-cloud-messagingreact-native-firebase

Firebase notification not arriving on iOS for FCM token with length 163


I am working on a react native project which uses FCM token to register a phone against a profile (not using Firebase Auth).

For android, FCM token generated is of length 152 and when I send a notification using Firebase Admin SDK, I receive the notification.

But for iOS, FCM token generated is of length 163. While using the same Java code to send notification, I get 404 error with "errorCode": "UNREGISTERED" and "message": "Requested entity was not found."

Push Notifications capability is added in Xcode. Notification listeners are also in place to handle notification if app is in foreground, background or closed.

I have tried to uninstall and then install the app. Even when a new FCM token is generated, the result is same. On the other hand, for some iOS devices (same iOS version), FCM token is generated with length 152 and I am able to send notification to those iPhones. I am unable to find out what is causing this issue on some iOS devices.

Expected: Notifications arriving on both android and iOS devices
Actual Result:
Notifications arriving on android.
Notifications arriving on iOS devices with FCM token length 152.
Notifications not arriving on iOS devices with FCM token length 163

Here are my configurations:
General:
iOS: 13.5.1
Model: iPhone XR
react-native: 0.62.2

Package.json:
"react-native-firebase": "^5.6.0",

Podfile:
pod 'Firebase/Core', '5.20.2'
pod 'Firebase/Messaging', '5.20.2'

Android/app build.gradle:
implementation "com.google.firebase:firebase-core:16.0.8"
implementation "com.google.firebase:firebase-messaging:17.6.0"


Solution

  • Got it working. For those who might face this issue, the problem was using NativeManager to fetch the FCM token.
    Previously I was fetching the token like this:

    nativeManager.getTokenString(CONSTANT_FCM_TOKEN, (fcmToken) => {...});
    

    Changed it to:

    fcmToken = await firebase.messaging().getToken();
    

    With firebase.messaging().getToken(), one FCM token is received first and then again RNFirebaseMessaging messaging:didReceiveRegistrationToken returns a new token. The new token is the one which is to be used.

    With NativeManager, only the first token was returned and that was not the correct token.