fcm icon indicating copy to clipboard operation
fcm copied to clipboard

Failed to get instance FirebaseID

Open grigala opened this issue 4 months ago • 0 comments

Hi all,

We are experiencing a weird token retrieval issue with error Failed to get instance FirebaseID when calling FCM.getToken() on iOS. Coming from: https://github.com/capacitor-community/fcm/blob/2cbc9169b150b34db25fb8c463d422feefc13ecd/ios/Plugin/Plugin.swift#L67

Does anybody have an idea what can be the cause of this error(I understand it could be many things) and is there anything that can be done?

The Android at the same time has no issue, only iOS it getting the error.

The AppDelegate.swift file is configured according to documentation https://capacitorjs.com/docs/guides/push-notifications-firebase#ios:

import UIKit
import Capacitor
import FirebaseCore
import FirebaseMessaging

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

  var window: UIWindow?

  //... other methods ...

  func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
    // Override point for customization after application launch.
    FirebaseApp.configure()
    return true
  }

  func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
    Messaging.messaging().apnsToken = deviceToken
    Messaging.messaging().token(completion: { (token, error) in
      if let error = error {
          NotificationCenter.default.post(name: .capacitorDidFailToRegisterForRemoteNotifications, object: error)
      } else if let token = token {
          NotificationCenter.default.post(name: .capacitorDidRegisterForRemoteNotifications, object: token)
      }
    })
  }

  func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {
    NotificationCenter.default.post(name: .capacitorDidFailToRegisterForRemoteNotifications, object: error)
  }

With Podfile correctly containing FirebaseMessaging pod dependency:

target 'App' do
  capacitor_pods
  # Add your Pods here
  pod 'FirebaseMessaging'
end

Could it be that we are still missing something in the configuration and thus Firebase not getting instantiated properly?

grigala avatar Sep 05 '25 14:09 grigala