firebase-ios-sdk: 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
About this issue
- Original URL
- State: closed
- Created a year ago
- Reactions: 24
- Comments: 64 (10 by maintainers)
Commits related to this issue
- WIP - pinpoint messaging issue https://github.com/firebase/firebase-ios-sdk/issues/10679#issuecomment-1397014629 — committed to invertase/react-native-firebase by mikehardy a year ago
- WIP - pinpoint messaging issue https://github.com/firebase/firebase-ios-sdk/issues/10679#issuecomment-1397014629 — committed to invertase/react-native-firebase by mikehardy a year ago
Hi all, I’ll be raising this to the team, and see what we can do here. Thanks.
Following up with some guidance for the Firebase 10.4.0 SDK.
As stated in the release notes, 10.4.0 onwards, we are declining vending a FCM token until an APNS token is provided. We have always been logging a WARNING when this has occurred in previous versions of the SDK but haven’t declined to provide a FCM token. Such a vended FCM token is not useful since it is missing a target APNS token and thus has no endpoint to send the pushes to.
Scenarios:
UPDATE Mar 1, 2023: This has been fixed in 10.6.0 - https://github.com/firebase/firebase-ios-sdk/pull/10789
func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String?)
If swizzling is disabled or if your project is pure SwiftUI (swizzling does not work well with SwiftUI projects) You must implement the UIApplicationDelegate callbacks to listen for APNS token availability. Check the SwiftUI sample in the FCM SDK codebase for how to achieve this.
Testing: If you have unit or integration tests running in the simulator, it is not possible to get an APNS token unless specific environment is used - iOS 16 Simulator + macOS 13 + Apple Silicon HW. If that environment condition is not met, there isn’t an APNS token available in iOS simulator. As a result, any tests for fetching FCM token will error out in the Firebase 10.4.0 SDK. Either reconsider the tests or try to provide fake APNS token for test purposes only. If you provide a fake APNS token, be sure to delete any FCM token created from this process. Example - the FIRMessagingPubSubTest in the Firebase SDK uses a fake APNS token.
facing same issue in my flutter app. FCM just stopped working with the following error
Can we say this is a firebase thingy for sure?
@aashishpatil-g It is understood, but they cannot make a change so drastic that it breaks applications that are already in production without sending a warning that they will make a change that can break functionality if they do not do the following
The same problem occurs with flutter applications using firebase_messaging
@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 solved it❗️
In fact, the notification
deviceToken(APNs Key)injection time was slower than the time to calltoken(_:).Like you, it happened a few days ago on iOS16 devices
You should check the timing of the called functions.
An update has been made to the Firebase SDK to provide an APN token at launch on the latest SDK release (https://firebase.google.com/support/release-notes/ios) Obviously, this modification applies even if we are not using the latest version of the SDK. This also applies to older versions which should not be the case…
Same issue here. We notice an error spike on firebase crashlytics as we send the error
This server change has been pulled back for now. It might take a few hours for it to propagate.
Yes, this is happening in production on IOS devices. Both simulators and real devices are causing the same error.
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' keyone.EDIT: didn’t fix it
But… @kishanbarmawala this reads the same as “I have decided to continue creating invalid FCM tokens in our project, by permanently relying on outdated versions of the software” - I mean that in a technical sense, I believe those are technically valid substitutions in your statement. I totally understand if it is just deferring the maintenance to a future date when project timelines allow but I would be careful adopting that version pin permanently…
I verify that things work now with firebase-ios-sdk for version 10.3.0 after rolling back the server change (thank you! That takes the pressure off us over at react-native-firebase, we appreciate it), but I still show an issue when attempting to qualify firebase-ios-sdk 10.4.0
Specifically, I see this when our e2e test suite exercises the Obj-C API and makes a call to deleteToken:
Okay, that appears to be somewhat expected based on the discussion in this issue and in the related changelog for 10.4.0 firebase-ios-sdk release, however, what I am personally missing (and thus cannot fix for the react-native-firebase community) is some guidance on exactly why the APNS token might be null (despite swizzling being in effect…) and how to forcibly fetch (or re-fetch) an APNS token in order to allow further work with FCM tokens
In our test app we are registered for remote notifications, so we should receive APNS tokens, and swizzling is on, so firebase-ios-sdk should be receiving the APNS tokens for messaging. I’m not sure what else we need to do to handle this change and adopt 10.4.0 but would love a hint
Thanks
[Update: our native code had conditionals that detected simulator and cut-out from the remote notification registration / APNS token fetch flows, so it would never get an APNS token of course! On an M1 mac with macOS 13 + iOS 16 Simulator we can get APNS tokens and everything works even on Simulator now when those conditions are met. We will fake an APNS token for other Simulators, and try to improve dev experience with better messaging for the other cases where APNS token may not be available]
The change log for Version 10.4.0 - January 17, 2023 says:
I tried this and it seems to be working for me as of Firebase v8.15:
Not sure if this is the right thing to do though. I hope Firebase updates their documentation to match the recent changes.
P.S. I also tried to find and upload my old APNs Auth Key and downloaded the
GoogleServices-info.plistfile (which turned out to be exactly same), therefore I don’t know if any of these actions were required in addition to the change in code I mentioned above.UPD: After the rollback the problem is gone from our live app, which is on Firebase 8.12. The build patched as described above and on Firebase 8.15 works fine as well.
@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.plistfiles 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.
@henryadebayo Just tried it too, and no change either.
@Seanmclem chaged APNs key Ali but it did not fix the issue maybe it may work you
I’m having the same issues, any tips on how to solve it?
Up here also. @aashishpatil-g if you can give us more infos about the case of this evolution will be live again. Which SDK version, when, etc… However thank you for reactivity
Yes I using Swift.
Using Swift. My app is Native app.
You shold check
Messaging.messaging ().apnsToken = deviceTokencalled timing, andMessaging.messaging().token(completion:)called timingIt’ll probably be called late
Messaging.messaging ().apnsToken = deviceTokenthanMessaging.messaging().token(completion:)because,
UNUserNotificationCenterDelegatebegan to receive late.I need to confirm this,
cause it seem to me that the error has to do with Simulator not being a physical device and returns
nullvalue as its APN token🤔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!
Similar issue: https://github.com/invertase/react-native-firebase/issues/6830