[go: nahoru, domu]

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

iOS ERROR with getToken "Error Domain=com.google.fcm Code=0 "Invalid fetch response, ..." #791

Closed
shinwenli opened this issue Jan 18, 2023 · 19 comments

Comments

@shinwenli
Copy link

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".

@shinwenli
Copy link
Author

It seems that there was a release like the following on the FCM side.
https://firebase.google.com/support/release-notes/ios#fcm

@dpa99c
Copy link
Owner
dpa99c commented Jan 18, 2023

Since this change was released in v10.4.0 of the Firebase iOS SDK, so long as you use v10.3.0 or earlier in your app, it should not affect you.
You can specify the SDK version during plugin installation.

@shinwenli
Copy link
Author

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.

@adirgan
Copy link
adirgan commented Jan 18, 2023

In my case, there is no way to get the FCM token, and everything changed from January 17, and my app has been in production for 2 months, and it just broke, since notifications are an important part of the app, I do not allow to log in without there being a token, and just as of yesterday in iOS no new installations log in anymore.

@adirgan
Copy link
adirgan commented Jan 18, 2023

I don't know how to solve obtaining the token, the problem happens no matter what version of FCM I have, the first thing I do when starting the app from 0 is to check if the permissions are there, if they aren't I request them, but this never runs .

@adirgan
Copy link
adirgan commented Jan 18, 2023

@shinwenli @dpa99c Have you found any solution to the problem?

@shinwenli
Copy link
Author

@adirgan As I already wrote, the interim workaround in my case was to catch the error that occurred in "window.FirebasePlugin.getToken" with "trycatch" and call "window.FirebasePlugin.getToken" again .
Is it not available in your environment?

@adirgan
Copy link
adirgan commented Jan 18, 2023

@shinwenli The same error keeps happening, apparently I have to get the APN token first before initializing the firebase autoStart

I'm trying to see how I can fix it

@shinwenli
Copy link
Author

@adirgan I'm sorry I can't help you.
I don't know if it's useful, but in my environment, there were cases where an error did not occur if an alert screen was displayed with "alert(1);" etc. before calling "getToken".
I'd like to do some more research myself.

@adirgan
Copy link
adirgan commented Jan 18, 2023

@shinwenli My problem is that I need push notifications, and I still can't find a way to obtain the token

@shinwenli
Copy link
Author

@adirgan In my case, the modal message to get permission for notifications was showing and then (after allowing notifications) I was getting an error.
Once the app was closed due to an error, the next time it was launched, it already had the authority (the token was issued), so restarting the app could avoid the problem.
If you look at the debug log in XCode, can't you get the token itself?

@adirgan
Copy link
adirgan commented Jan 18, 2023

@shinwenli I'm looking at what the correct order is, if first ask for permission, and then try to get the APN token, I'm not sure, the log still doesn't show anything useful

@adirgan
Copy link
adirgan commented Jan 19, 2023

@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

@shinwenli
Copy link
Author

Earlier, when I started the app that had the error (no countermeasures were taken), it was confirmed that it started normally.
Perhaps it was a bug on the FCM side and FCM fixed it.

@dpa99c @adirgan Thank you for all the information.
This solved the issue that I was having trouble with.

@adirgan
Copy link
adirgan commented Jan 19, 2023

@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
Copy link
Author

@adirgan That information is very informative for me. I thought that "getToken()" was the flow of processing to get even the APNs token. So, does Firebase currently send push notifications from FCM without APNs tokens?
Thank you, I will learn a lot.

@adirgan
Copy link
adirgan commented Jan 19, 2023

@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
Copy link
Author

@adirgan With the latest SDK released the other day, I was able to learn that it is necessary to acquire APNs first as you said.
Even the latest SDK can be handled by using firebasex's "getAPNSToken" and "onApnsTokenReceived", so I think this is very important information. thank you.

@adirgan
Copy link
adirgan commented Jan 19, 2023

@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.

firebase/firebase-ios-sdk#10679

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants