InstanceID token() no longer works in a Swift Firebase app
InstanceID is deprecatedShort 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.
Fix it fast
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 .2Match what you see, then jump to its fix
- 1
A compile error or warning on InstanceID in a Swift fileCode still calls InstanceID.instanceID() to read the tokenFix - 2
The token is nil early at launch, or your server holds an outdated tokenThe token is read once instead of through the refresh delegateFix - 3
InstanceID shows up in Podfile or Podfile.lockThe Podfile still pulls the old FirebaseInstanceID podFix
- 1
What does the error look like?
InstanceID is deprecatedInstance 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
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 launchConfirmed by firebase.google.com
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.lock2Fix
Remove the pod line and reinstall.
pod install3Verify
Podfile.lock no longer lists FirebaseInstanceID and the project builds.
grep -c "FirebaseInstanceID" Podfile.lockConfirmed by raw.githubusercontent.com
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:
- SessionBirdAn omnichannel engagement suite in Flutter: campaigns, chatbot, tickets, analytics and live calling.
- WorkforceA field app, an admin console and a self-hosted Node.js server for push and reconciliation.
- Dawlance AirA companion app for smart air conditioners, with IoT pairing across native and Flutter layers.
Related fixes
Mobile apps
Firebase on iOS asks for the FCM token before APNs has given one
Be sure to re-retrieve the FCM token once the APNS device token is set.
The Firebase Messaging SDK needs the APNs device token from iOS before it hands out an FCM token.
3 causes, each with a fixMobile apps
FirebaseInstanceIdService and FirebaseInstanceId.getToken() no longer work
Deprecation warning on FirebaseInstanceId.getInstance().getToken()
Move token handling into a class that extends FirebaseMessagingService and override onNewToken, which runs when a token is first created and whenever it changes.
2 causes, each with a fixMobile apps
A test push from the Firebase console never shows up on the iPhone
didReceiveRegistrationToken prints a token, yet no notification arrives
When a console message is accepted but the iPhone stays silent, the break is between Firebase and APNs or inside the app.
4 causes, each with a fixMobile apps
CocoaPods refuses a Swift pod that depends on a pod without modules
... does not define modules.
CocoaPods builds Swift pods as static libraries only if every pod they import defines a module.
2 causes, each with a fixMobile apps
Xcode builds no dSYM for the app, so Crashlytics shows missing dSYMs
error: Info.plist Error Unable to process Info.plist
Crashlytics needs a dSYM from every build.
4 causes, each with a fixMobile apps
Xcode cannot find the Firebase module inside a framework or library
No such module 'Firebase'
A target only sees the pods declared for it.
3 causes, each with a fix