cordova-plugin-firebasex: iOS ERROR with getToken "Error Domain=com.google.fcm Code=0 "Invalid fetch response, ..."

From today, my app has received many error reports from iOS users. The error message is as follows.

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}

Probably, it occurs at the time of the following function call

    window.FirebasePlugin.getToken

The error handling that is the second argument of “getToken” is called and the error of “Error Domain=com.google.fcm Code=0…” is passed. This is where the app throws an error. However, as far as chasing the logs in XCode, the token itself seems to have been acquired afterwards. A log of “didRecievedRegistrationToken …” was being obtained. If I then restarted the application, I was able to get the token and continue processing without error.

Maybe it’s a problem on the Firebase side. Do you have any information? The Firebasex plugin version I’m currently using is 14.2.1.

In addition, as a workaround for the time being, it seems possible to start normally by calling “window.FirebasePlugin.getToken” again in the error handling using “try catch”.

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Comments: 19 (1 by maintainers)

Most upvoted comments

@shinwenli Right now doing tests, apparently they put it back as before, that is, if you have an older version of SDK FCM than 10.4.0, you can continue working with getToken(), they just changed it about 20 minutes ago, but I think it’s important work as I told you before and update to version 10.4.0, so as not to have problems in the future.

https://github.com/firebase/firebase-ios-sdk/issues/10679

the last comment indicated that they made a pullback of the changes made to the server

@shinwenli It was like that until 2 days ago, but with this change in the SDK API, it is no longer possible to do that, now you always have to obtain the APN Token first and then use getToken()

Before when I let you create the FCM Token without the APN, a notification would never arrive to that phone, but before when you used the getToken() after requesting the notification permission it was automatic that it created the APN, now you just have to do the logic complete oneself

@shinwenli Yes, it is indeed a problem that FCM originated, but for them it is not a bug, and what they want, according to what I see on github, is that in their DB there are no FCM Tokens without APN Tokens, and that is why now it is mandatory that the APN always be there. token first

@shinwenli I tell you that I already found the solution, the first thing you have to do is use these 2 functions, hasPermission and grantPermission, if the permission is accepted you use these functions getAPNSToken and onApnsTokenReceived, the last function is an observable, at the moment that this observable gives you return the ios APN token, then you can already get the FCM token without any problem.

And with that everything is solved, you will always get the token, if you have the permission and you have the APN Token first.

Checking the Firabase SDK iOS github, the problem is that they changed the Firebase backend API, and the API no longer accepts saving an FCM token without which the APN is created first, therefore you always have to verify that have the permissions and request the APN token before requesting the FCM Token

Thank you for the information.

However, the error suddenly occurred even though there was no particular update, etc. for the already released app. It might be a bug or something on the FCM side that accompanies that change. For the time being, I will try to avoid it with “try catch”, but if you find out anything new, I would be grateful if you could let me know.