Messaging.messaging().token returns errors
Description
It has been two days since that last Messaging.messaging().token success with our app.
It currently returns the following error :
Error Domain=com.google.fcm Code=0 "Invalid fetch response, expected 'token' or 'Error' key" UserInfo={NSLocalizedFailureReason=Invalid fetch response, expected 'token' or 'Error' key}
Here is how we retrieve the token :
self.getMessaging().token { token, error in
if let error = error {
Logger.shared.log(.app, .error, "Error fetching FCM registration token: \(error)")
observer(.failure(error))
} else if let token = token {
Logger.shared.log(.app, .debug, "FCM registration token: \(token)")
observer(.success(token))
}
}
return Disposables.create()
Note 1: the live app has not been updated since 2 weeks and we reproduce the same issue with oldest version.
Note 2: We have a different target using the same code with a different bundle id which does not have the issue.
Reproducing the issue
No response
Firebase SDK Version
10.3.0
Xcode Version
14.1
Installation Method
CocoaPods
Firebase Product(s)
Messaging
Targeted Platforms
iOS
Relevant Log Output
Error Domain=com.google.fcm Code=0 "Invalid fetch response, expected 'token' or 'Error' key" UserInfo={NSLocalizedFailureReason=Invalid fetch response, expected 'token' or 'Error' key}
If using Swift Package Manager, the project's Package.resolved
Expand Package.resolved snippet
Replace this line with the contents of your Package.resolved.
If using CocoaPods, the project's Podfile.lock
Expand Podfile.lock snippet
PODS:
- Alamofire (5.6.4)
- Differentiator (5.0.0)
- Firebase/AnalyticsWithoutAdIdSupport (10.3.0):
- Firebase/CoreOnly
- FirebaseAnalytics/WithoutAdIdSupport (~> 10.3.0)
- Firebase/CoreOnly (10.3.0):
- FirebaseCore (= 10.3.0)
- Firebase/Crashlytics (10.3.0):
- Firebase/CoreOnly
- FirebaseCrashlytics (~> 10.3.0)
- Firebase/Messaging (10.3.0):
- Firebase/CoreOnly
- FirebaseMessaging (~> 10.3.0)
- FirebaseAnalytics/WithoutAdIdSupport (10.3.0):
- FirebaseCore (~> 10.0)
- FirebaseInstallations (~> 10.0)
- GoogleAppMeasurement/WithoutAdIdSupport (= 10.3.0)
- GoogleUtilities/AppDelegateSwizzler (~> 7.8)
- GoogleUtilities/MethodSwizzler (~> 7.8)
- GoogleUtilities/Network (~> 7.8)
- "GoogleUtilities/NSData+zlib (~> 7.8)"
- nanopb (< 2.30910.0, >= 2.30908.0)
- FirebaseCore (10.3.0):
- FirebaseCoreInternal (~> 10.0)
- GoogleUtilities/Environment (~> 7.8)
- GoogleUtilities/Logger (~> 7.8)
- FirebaseCoreInternal (10.3.0):
- "GoogleUtilities/NSData+zlib (~> 7.8)"
- FirebaseCrashlytics (10.3.0):
- FirebaseCore (~> 10.0)
- FirebaseInstallations (~> 10.0)
- GoogleDataTransport (~> 9.2)
- GoogleUtilities/Environment (~> 7.8)
- nanopb (< 2.30910.0, >= 2.30908.0)
- PromisesObjC (~> 2.1)
- FirebaseInstallations (10.3.0):
- FirebaseCore (~> 10.0)
- GoogleUtilities/Environment (~> 7.8)
- GoogleUtilities/UserDefaults (~> 7.8)
- PromisesObjC (~> 2.1)
- FirebaseMessaging (10.3.0):
- FirebaseCore (~> 10.0)
- FirebaseInstallations (~> 10.0)
- GoogleDataTransport (~> 9.2)
- GoogleUtilities/AppDelegateSwizzler (~> 7.8)
- GoogleUtilities/Environment (~> 7.8)
- GoogleUtilities/Reachability (~> 7.8)
- GoogleUtilities/UserDefaults (~> 7.8)
- nanopb (< 2.30910.0, >= 2.30908.0)
- GoogleAppMeasurement/WithoutAdIdSupport (10.3.0):
- GoogleUtilities/AppDelegateSwizzler (~> 7.8)
- GoogleUtilities/MethodSwizzler (~> 7.8)
- GoogleUtilities/Network (~> 7.8)
- "GoogleUtilities/NSData+zlib (~> 7.8)"
- nanopb (< 2.30910.0, >= 2.30908.0)
- GoogleDataTransport (9.2.0):
- GoogleUtilities/Environment (~> 7.7)
- nanopb (< 2.30910.0, >= 2.30908.0)
- PromisesObjC (< 3.0, >= 1.2)
- GoogleUtilities/AppDelegateSwizzler (7.11.0):
- GoogleUtilities/Environment
- GoogleUtilities/Logger
- GoogleUtilities/Network
- GoogleUtilities/Environment (7.11.0):
- PromisesObjC (< 3.0, >= 1.2)
- GoogleUtilities/Logger (7.11.0):
- GoogleUtilities/Environment
- GoogleUtilities/MethodSwizzler (7.11.0):
- GoogleUtilities/Logger
- GoogleUtilities/Network (7.11.0):
- GoogleUtilities/Logger
- "GoogleUtilities/NSData+zlib"
- GoogleUtilities/Reachability
- "GoogleUtilities/NSData+zlib (7.11.0)"
- GoogleUtilities/Reachability (7.11.0):
- GoogleUtilities/Logger
- GoogleUtilities/UserDefaults (7.11.0):
- GoogleUtilities/Logger
- IQKeyboardManager (6.5.10)
- Kingfisher (7.4.1)
- Moya (15.0.0):
- Moya/Core (= 15.0.0)
- Moya/Core (15.0.0):
- Alamofire (~> 5.0)
- Moya/RxSwift (15.0.0):
- Moya/Core
- RxSwift (~> 6.0)
- nanopb (2.30909.0):
- nanopb/decode (= 2.30909.0)
- nanopb/encode (= 2.30909.0)
- nanopb/decode (2.30909.0)
- nanopb/encode (2.30909.0)
- NSLogger/ObjC (1.9.7)
- NSLogger/Swift (1.9.7):
- NSLogger/ObjC
- PromisesObjC (2.1.1)
- RxBlocking (6.5.0):
- RxSwift (= 6.5.0)
- RxCocoa (6.5.0):
- RxRelay (= 6.5.0)
- RxSwift (= 6.5.0)
- RxDataSources (5.0.0):
- Differentiator (~> 5.0)
- RxCocoa (~> 6.0)
- RxSwift (~> 6.0)
- RxGesture (4.0.4):
- RxCocoa (~> 6.0)
- RxSwift (~> 6.0)
- RxRelay (6.5.0):
- RxSwift (= 6.5.0)
- RxSwift (6.5.0)
- RxSwiftExt (6.0.1):
- RxSwiftExt/Core (= 6.0.1)
- RxSwiftExt/RxCocoa (= 6.0.1)
- RxSwiftExt/Core (6.0.1):
- RxSwift (~> 6.0)
- RxSwiftExt/RxCocoa (6.0.1):
- RxCocoa (~> 6.0)
- RxSwiftExt/Core
- RxTest (6.5.0):
- RxSwift (= 6.5.0)
- SwiftLint (0.49.1)
- SwiftyAttributes (5.1.1)
DEPENDENCIES:
- Firebase/AnalyticsWithoutAdIdSupport
- Firebase/Crashlytics
- Firebase/Messaging
- IQKeyboardManager (~> 6.5.9)
- Kingfisher (~> 7.4.1)
- Moya (~> 15.0.0)
- Moya/RxSwift (~> 15.0.0)
- NSLogger/Swift
- RxBlocking (~> 6.5.0)
- RxCocoa (~> 6.5.0)
- RxDataSources (~> 5.0.0)
- RxGesture (~> 4.0.4)
- RxSwift (~> 6.5.0)
- RxSwiftExt (~> 6.0.1)
- RxTest (~> 6.5.0)
- SwiftLint (~> 0.49.1)
- SwiftyAttributes (~> 5.1.1)
SPEC REPOS:
https://github.com/CocoaPods/Specs.git:
- Alamofire
- Differentiator
- Firebase
- FirebaseAnalytics
- FirebaseCore
- FirebaseCoreInternal
- FirebaseCrashlytics
- FirebaseInstallations
- FirebaseMessaging
- GoogleAppMeasurement
- GoogleDataTransport
- GoogleUtilities
- IQKeyboardManager
- Kingfisher
- Moya
- nanopb
- NSLogger
- PromisesObjC
- RxBlocking
- RxCocoa
- RxDataSources
- RxGesture
- RxRelay
- RxSwift
- RxSwiftExt
- RxTest
- SwiftLint
- SwiftyAttributes
SPEC CHECKSUMS:
Alamofire: 4e95d97098eacb88856099c4fc79b526a299e48c
Differentiator: e8497ceab83c1b10ca233716d547b9af21b9344d
Firebase: f92fc551ead69c94168d36c2b26188263860acd9
FirebaseAnalytics: 036232b6a1e2918e5f67572417be1173576245f3
FirebaseCore: 988754646ab3bd4bdcb740f1bfe26b9f6c0d5f2a
FirebaseCoreInternal: 29b76f784d607df8b2a1259d73c3f04f1210137b
FirebaseCrashlytics: f20d956f8229010b645e534693c39e0b7843c268
FirebaseInstallations: e2f26126089dcf41e215f7b8925af8d953c7d602
FirebaseMessaging: e345b219fd15d325f0cf2fef28cb8ce00d851b3f
GoogleAppMeasurement: c7d6fff39bf2d829587d74088d582e32d75133c3
GoogleDataTransport: 1c8145da7117bd68bbbed00cf304edb6a24de00f
GoogleUtilities: c2bdc4cf2ce786c4d2e6b3bcfd599a25ca78f06f
IQKeyboardManager: 45a1fa55c1a5b02c61ac0fd7fd5b62bb4ad20d97
Kingfisher: cd762a593a61b2fbecf7645c00f9a801a3ebfc9c
Moya: 138f0573e53411fb3dc17016add0b748dfbd78ee
nanopb: b552cce312b6c8484180ef47159bc0f65a1f0431
NSLogger: cf3013a4fba189f631f07e6c3d5b8ce2b209654b
PromisesObjC: ab77feca74fa2823e7af4249b8326368e61014cb
RxBlocking: 04b5fd28bb5ea49f7d64b80db8bbfe50d9cc1c7d
RxCocoa: 94f817b71c07517321eb4f9ad299112ca8af743b
RxDataSources: aa47cc1ed6c500fa0dfecac5c979b723542d79cf
RxGesture: f3efb47ed2d26a8082f7b660d4a59970e275a7f8
RxRelay: 1de1523e604c72b6c68feadedd1af3b1b4d0ecbd
RxSwift: 5710a9e6b17f3c3d6e40d6e559b9fa1e813b2ef8
RxSwiftExt: d61c4b9b06e0a448041b1c659e0f1b5c5a035afc
RxTest: eb2d23adefc5a5ebf5779c7792fa3edfe6ebcc17
SwiftLint: 32ee33ded0636d0905ef6911b2b67bbaeeedafa5
SwiftyAttributes: e3e13891ddac3c62b3d7798d5c3969cea88e62bb
PODFILE CHECKSUM: e2e890938470dccb8e731dbb945147be1c8c971c
COCOAPODS: 1.11.3
I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.
Similar issue: https://github.com/invertase/react-native-firebase/issues/6830
@RobinCaroff Thanks for opening this one and cross-referencing 🙇
While not directly related, it seems contextually interesting that we have started seeing some other previously non-existent behaviors with the Firebase Messaging SDK/React Native Firebase Messaging.
We were doing some regression testing for an upgrade of our RN Instabug integration in the App, and encountered another errors on iOS, which we had never seen "surfaced" to our error reporting:
[messaging/unknown] The Internet connection appears to be offline.This message was logged as part of a scenario were we deliberately took down the network (router offline for Wifi). Historically, I suspect, this might have been handled "silently" by the Messaging SDK?
Again, just for context if that helps narrow down how the messaging.getToken() issue made it into a codebase that had not updated Firebase dependencies when the error started to occur.
having the same issue as @RobinCaroff how do i resolve it ?
I'm having the same issues, any tips on how to solve it?
Hi all, I tried to reproduce the issue but I was able to retrieve the token successfully. With this, could you share a minimal repro app as well as the complete stack trace or app debug logs for further investigation?
Hi all, I tried to reproduce the issue but I was able to retrieve the token successfully. With this, could you share a minimal repro app as well as the complete stack trace or app debug logs for further investigation?
Hi @rizafran . Thank you for your answer. What's really strange is that I also use the same codebase with a different bundle id (my preprod environment) and I don't get the error. I checked the Firebase plist but it is up to date.
I'll try to produce a minimal repo where I can reproduce the error. In the meantime, is there any specific Firebase log that I could provide to help you narrow down the issue?
Also ran into this. I have tried various versions of the firebase pod during the installation of the plugin and still facing the error on emulators as well as production environments.
What's really strange is that I also use the same codebase with a different bundle id (my preprod environment) and I don't get the error. I checked the Firebase plist but it is up to date.
This makes it even more curious, since the same exact thing is happening to me. In one of the environments it works flawlessly, the other is failing constantly!
Having the same issue. No idea what's happening. Started all of a sudden.
Same issue here. We notice an error spike on firebase crashlytics as we send the error

Can we say this is a firebase thingy for sure?
Maybe Certs are expired...the Apple APN keys are setup, and my Dev and Prod ones are invalid. One in expired last month in December, and the prod one expired Today.
This was the exact error I was getting. the expected 'token' or 'Error' key one.
EDIT: didn't fix it
@Seanmclem chaged APNs key Ali but it did not fix the issue maybe it may work you
@henryadebayo Just tried it too, and no change either.
So serious problem
@Seanmclem and @yeahse so i removed the GoogleServices-info.plist file from my Runner folder, then i did flutter clean and clean build folder then flutter pub get and it worked, yet to replace the GoogleServices-info.plist file , i i'm thinking the GoogleServices-info.plist file is corrupt don't know how or if this ever happens will replace it and let you know if it still works
@henryadebayo I was able to fix it based on your reply, so thanks! However, I was thinking about the plist thing -and felt like it was unlikely that all of our GoogleServices-info.plist files are suddenly corrupt in the past 5 days. So rather than deleting it -I did the other part you mentioned. I stopped and restarted my app. Not even a full rebuild, just a new JS bundle (I'm using React Native), so a quick stop and restart, also closed and re-opened simulator.
The only other thing we have in common is we both just re-added our APN certificates. So that might be required too, but afterwards restarting the build was definitely the final thing that fixed it for me.
We are using Firebase Unity SDK 9.40, which wraps Firebase iOS SDK, and we are experiencing the same problem as the issue in this article, so we leave an opinion.
In the past week, 2 out of 15 apps in service were only on iOS.
- All apps use the same code
- App crash occurs while the app starts with the error described in this article
The method we implemented was implemented in items 1 and 2 below.
-
Obtain a token by registering an event like the guide at https://firebase.google.com/docs/cloud-messaging/unity/client#initialize
-
If the token was not obtained in method 1, acquire the token by additionally implementing the https://stackoverflow.com/a/69222193/13368553 method
In one app, the app crash was fixed by removing 2, but in the other app, even if 2 was removed, it was not fixed, so the code implemented in 1 was deleted to respond.
Today, we're facing the same issue with the rest of the apps, and we're going to respond the same way we finally responded.
However, if you respond in this way, you will not be able to use FCM, so you need to respond quickly.
@Seanmclem and @yeahse so i removed the GoogleServices-info.plist file from my Runner folder, then i did flutter clean and clean build folder then flutter pub get and it worked, yet to replace the GoogleServices-info.plist file , i i'm thinking the GoogleServices-info.plist file is corrupt don't know how or if this ever happens will replace it and let you know if it still works
I just followed your solution and it does not work