Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Flutter and app store releases

InstanceID token() no longer works in a Swift Firebase app

ErrorInstanceID is deprecated

Short answer

Firebase removed the Instance ID dependency from Messaging in 8.0.0, so InstanceID.instanceID() calls no longer belong in a current app. Read the registration token through the Messaging delegate callback or Messaging.messaging().token, and remove the FirebaseInstanceID pod from the Podfile.

  • Applies to Xcode 26, firebase-ios-sdk 12, Swift 6
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Find every place the old API is still used, and check whether the old pod is still listed.

    grep -rn "InstanceID" --include=*.swift --include=Podfile .
  2. 2Match what you see, then jump to its fix

    1. 1A compile error or warning on InstanceID in a Swift fileCode still calls InstanceID.instanceID() to read the tokenFix
    2. 2The token is nil early at launch, or your server holds an outdated tokenThe token is read once instead of through the refresh delegateFix
    3. 3InstanceID shows up in Podfile or Podfile.lockThe Podfile still pulls the old FirebaseInstanceID podFix

What does the error look like?

  • InstanceID is deprecated
  • Instance ID calls fail to compile after upgrading Firebase to 8.0.0 or later

Cause 1 of 3

Code still calls InstanceID.instanceID() to read the token

1Check

The Firebase Messaging changelog records InstanceID as deprecated in 4.7.1 and removed as a Messaging dependency in 8.0.0. The current guide reads the token from Messaging.

grep -rn "instanceID()" --include=*.swift .

2Fix

Replace the call with the Messaging token API. It returns the token or an error in a completion handler.

Messaging.messaging().token { token, error in
    if let error = error {
        print("Error fetching FCM registration token: \(error)")
    } else if let token = token {
        print("FCM registration token: \(token)")
    }
}

3Verify

Build and run; the token prints and the InstanceID error is gone.

# Xcode console: FCM registration token: ...

Confirmed by firebase.google.com

Did this fix it?

Cause 2 of 3

The token is read once instead of through the refresh delegate

1Check

The guide says the delegate method runs at each app start and whenever a new token is generated, so it is the place to store tokens. Check that your AppDelegate sets Messaging.messaging().delegate.

grep -rn "didReceiveRegistrationToken" --include=*.swift .

2Fix

Set the delegate after FirebaseApp.configure() and upload the token to your server inside the callback.

Messaging.messaging().delegate = self

extension AppDelegate: MessagingDelegate {
    func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String?) {
        // send fcmToken to your server
    }
}

3Verify

Reinstall the app and watch your server receive the new token on first launch.

# check the token row on your server after launch

Confirmed by firebase.google.com

Did this fix it?

Cause 3 of 3

The Podfile still pulls the old FirebaseInstanceID pod

1Check

Since Messaging 8.0.0 it does not depend on InstanceID, so a pod that remains is only there because you added it.

grep -n "InstanceID" Podfile Podfile.lock

2Fix

Remove the pod line and reinstall.

pod install

3Verify

Podfile.lock no longer lists FirebaseInstanceID and the project builds.

grep -c "FirebaseInstanceID" Podfile.lock

Confirmed by raw.githubusercontent.com

Did this fix it?

How do I stop it coming back?

  • Read release notes of FirebaseMessaging before bumping the major version.
  • Treat the token as changeable: store it from the delegate callback each time it fires.
  • Note that Firebase's guide now marks token APIs as deprecated in favour of Firebase Installation IDs, so keep token reads in one small wrapper.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.