简体   繁体   中英

Error : messaging/registration-token-not-registered

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) 在此处输入图像描述 (Already create in Certificates, Identifiers & Profiles of my Apple developper account) 在此处输入图像描述

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: 在此处输入图像描述 PostMan log:

在此处输入图像描述

BTW it works fine for android

This error happens when the FCM token that's been trying to be sent not registered anymore, given by the "messaging/registration-token-not-registered" error code. You can try removing this token from the user's token and see if it works.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM