Error : messaging/registration-token-not-registered

4,327 views
Skip to first unread message

Jeremy Dormevil

unread,
Jun 22, 2020, 10:38:51 AM6/22/20
to Flutter Development (flutter-dev)

Would anyone be why i get this error when i try to send a notification to a Iphone Physical device ??

Error sending message { Error: Requested entity was not found.
    at FirebaseMessagingError.FirebaseError [as constructor] (/srv/node_modules/firebase-admin/lib/utils/error.js:42:28)
    at FirebaseMessagingError.PrefixedFirebaseError [as constructor] (/srv/node_modules/firebase-admin/lib/utils/error.js:88:28)
at new FirebaseMessagingError (/srv/node_modules/firebase-admin/lib/utils/error.js:254:16)
    at Function.FirebaseMessagingError.fromServerError (/srv/node_modules/firebase-admin/lib/utils/error.js:287:16)
    at Object.createFirebaseError (/srv/node_modules/firebase-admin/lib/messaging/messaging-errors.js:34:47)
    at /srv/node_modules/firebase-admin/lib/messaging/messaging-api-request.js:76:42
    at <anonymous>
    at process._tickDomainCallback (internal/process/next_tick.js:229:7)
  errorInfo: 
   { code: 'messaging/registration-token-not-registered',
     message: 'Requested entity was not found.' },
  codePrefix: 'messaging' }

It's saying that my registration token is not registered. After looking into the firebase doc i saw that : https://firebase.google.com/docs/cloud-messaging/send-message#admin_sdk_error_reference

messaging/registration-token-not-registered :

The provided registration token is not registered. A previously valid registration token can be unregistered for a variety of reasons, including:

  • The client app unregistered itself from FCM
  • The client app was automatically unregistered.(This can happen if the user uninstalls the application or, on iOS, if the APNS Feedback Service reported the APNS token as invalid.)
  • The registration token expired. (For example, Google might decide to refresh registration tokens or the APNS token may have expired for iOS devices.)
  • The client app was updated, but the new version is not configured to receive messages.

For all these cases, remove this registration token and stop using it to send messages.

But i feel like i already filled all the requirement (APNS is already configured and added into Firebase console) enter image description here (Already create in Certificates, Identifiers & Profiles of my Apple developper account) enter image description here

I even add the code that ask for user permission (It also works, when i test it on my device)

  getIOSPermission() {
    _firebaseMessaging.requestNotificationPermissions(
        IosNotificationSettings(alert: true, badge: true, sound: true));
    _firebaseMessaging.onIosSettingsRegistered.listen((settings) {
      print("Settings registered:$settings");
    });
  }

  void requestIOSPermissions() {
    flutterLocalNotificationsPlugin
        .resolvePlatformSpecificImplementation<
            IOSFlutterLocalNotificationsPlugin>()
        ?.requestPermissions(
          alert: true,
          badge: true,
          sound: true,
        );
  }

if (Platform.isIOS) {
  getIOSPermission();
  requestIOSPermissions();
}
_firebaseMessaging.getToken().then((token) {
  print("Firebase Messaging Token: $token\n");
  usersRef
      .document(firebaseUser.uid)
      .updateData({"androidNotificationToken": token});
});

I also followed all the steps specified in the FCM package readme about the IOS Integration. https://pub.dev/packages/firebase_messaging

Here my AppDelegate.swift code :

import UIKit
import Flutter

@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
  override func application(
    _ application: UIApplication,
    didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
  ) -> Bool {
    if #available(iOS 10.0, *) {
      UNUserNotificationCenter.current().delegate = self as? UNUserNotificationCenterDelegate
    }
    GeneratedPluginRegistrant.register(with: self)
    return super.application(application, didFinishLaunchingWithOptions: launchOptions)
  }
}

Any idea why i still get this error ?

Fcm log: enter image description here PostMan log :

enter image description here

BTW it works fine for android

Reply all
Reply to author
Forward
0 new messages