Firebase on iOS asks for the FCM token before APNs has given one
APNS device token not set before retrieving FCM Token for Sender IDShort answer
The Firebase Messaging SDK needs the APNs device token from iOS before it hands out an FCM token. If your code asks too early, if the APNs token never reaches Firebase, or if iOS never issues one, you get this message. Read the token in the delegate callback, map the APNs token yourself when swizzling is off, and check the push capability.
Fix it fast
1Find out which cause you have
Log both tokens in one place. If the APNs line never prints, iOS has not issued a token and the problem is registration. If it prints after the FCM error, the problem is order.
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) { print("APNs token received, \(deviceToken.count) bytes") } func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) { print("APNs registration failed: \(error)") }2Match what you see, then jump to its fix
- 1
The message appears once at launch, and the APNs line prints after itThe FCM token is requested before the APNs token has arrivedFix - 2
The APNs line prints, but the Firebase message still appearsMethod swizzling is off, or the app is SwiftUI, so Firebase never sees the APNs tokenFix - 3
didFailToRegisterForRemoteNotificationsWithError prints, or no APNs line prints at alliOS never issues an APNs token because registration fails or is never requestedFix
- 1
What does the error look like?
APNS device token not set before retrieving FCM Token for Sender IDBe sure to re-retrieve the FCM token once the APNS device token is set.
Cause 1 of 3
The FCM token is requested before the APNs token has arrived
1Check
Search the code for Messaging.messaging().token calls that run in didFinishLaunching or in a view's onAppear. The SDK logs this message when it starts a token fetch while it has no APNs token. Its release notes say that since 10.4.0 an APNs token must be provided on startup before an FCM token is retrieved.
grep -rn "Messaging.messaging().token" --include=*.swift .2Fix
Do not poll for the token at launch. Set the messaging delegate after FirebaseApp.configure() and let the SDK call you when the token exists. It fires at each app start and whenever a new token is generated. Send the token to your server from that callback.
func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
FirebaseApp.configure()
Messaging.messaging().delegate = self
return true
}
extension AppDelegate: MessagingDelegate {
func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String?) {
print("FCM token: \(fcmToken ?? "nil")")
}
}3Verify
Run on a real iPhone. The callback prints a token and the warning no longer appears after the APNs line.
# Xcode console: look for 'APNs token received' followed by 'FCM token:'Confirmed by raw.githubusercontent.com
Cause 2 of 3
Method swizzling is off, or the app is SwiftUI, so Firebase never sees the APNs token
1Check
Firebase maps the APNs token to its own token by swizzling app delegate methods. It is switched off when Info.plist has FirebaseAppDelegateProxyEnabled set to NO, and Firebase's guide says SwiftUI apps must do the mapping by hand.
grep -rn "FirebaseAppDelegateProxyEnabled" --include=Info.plist .2Fix
Hand the APNs token to Firebase yourself in the delegate method that receives it.
func application(_ application: UIApplication,
didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
Messaging.messaging().apnsToken = deviceToken
}3Verify
Launch again: the FCM token callback from the first cause now fires without the warning.
# Xcode console: the 'FCM token:' line prints onceConfirmed by firebase.google.com
Cause 3 of 3
iOS never issues an APNs token because registration fails or is never requested
1Check
Apple lists the reasons registration can fail: no network, APNs unreachable, or the app lacks the right code-signing entitlement. Open Signing & Capabilities and look for Push Notifications, which adds aps-environment. Also confirm the code calls registerForRemoteNotifications().
grep -rn "registerForRemoteNotifications" --include=*.swift .2Fix
Add the Push Notifications capability to the app target and enable push for the App ID in your developer account. Call registerForRemoteNotifications() after the user answers the permission prompt.
UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound, .badge]) { granted, _ in
guard granted else { return }
DispatchQueue.main.async {
UIApplication.shared.registerForRemoteNotifications()
}
}3Verify
Rebuild, run on a device and confirm the 'APNs token received' line prints.
# Xcode console: 'APNs token received, 32 bytes'Confirmed by developer.apple.com
How do I stop it coming back?
- Treat the FCM token as something the SDK delivers to a delegate, not something you read once at launch.
- Always implement didFailToRegisterForRemoteNotificationsWithError and log the error.
- Test push code on a physical device, and keep the Push Notifications capability in the project, not only in a local setup.
- If you turn swizzling off, write the apnsToken line in the same commit.
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
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
FCM cannot reach an iPhone: APNs or web push credentials rejected
HTTP 401 when sending to an iOS registration token
THIRD_PARTY_AUTH_ERROR is HTTP 401.
2 causes, each with a fixMobile apps
The iOS push arrives from FCM but plays no sound
A custom sound name in the payload is ignored and nothing plays
iOS plays a sound for a remote notification only when the aps payload has a sound key and the app is allowed to play sounds.
3 causes, each with a fixMobile apps
InstanceID token() no longer works in a Swift Firebase app
Instance ID calls fail to compile after upgrading Firebase to 8.0.0 or later
Firebase removed the Instance ID dependency from Messaging in 8.0.0, so InstanceID.instanceID() calls no longer belong in a current app.
3 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 fix