-
Notifications
You must be signed in to change notification settings - Fork 2.2k
[iOS][FCM] Cannot get new token when use 'messaging().deleteToken()' #3714
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
Comments
Just a guess, have you tried waiting / retrying and seeing if it changes? Hypothesis could be wrong but easy test to run |
@mikehardy Yes, I have tried and reload the app again but still got the same value. It happen only iOS, for android it’s working find |
I don't mean "reload", I mean in the very same execution context - not with an app reload that would call deleteToken again, after a single delete call, retrying the fetch token a few times (with exponential back-off maybe) to see if it changes underneath the code |
@mikehardy Yes, I mean I have tried it both. const token1 = await messaging().getToken();
console.log(token1);
await messaging().deleteToken();
const token2 = await messaging().getToken();
console.log(token2);
const token3 = await messaging().getToken();
console.log(token3);
const token4 = await messaging().getToken();
console.log(token4);
const token5 = await messaging().getToken();
console.log(token5); still got the same token. When I try to reload app, it still got same token as before I reload and after that the token cannot use to register anymore. I need to tell that everything working fine with Android but this issue happen only iOS. I'm not sure which method that is at issue |
There is no sleep there, add a multi-second sleep, imagine network latency, replicated databases doing a 2-phase commit with consensus on multiple nodes in the apple cloud etc to persist the token - the hypothesis is it could take a couple seconds to come back. Wait as long as a minute maybe between the delete call and the final token log to really see if it is some cloud process Sorry to pester I just don't think the awaits here are enough to be the test I was looking for yet |
@mikehardy I have already tried to sleep 1 minute is it enough for you? and if it's related to response time, why everything working fine |
1 minute's good - thank you. Difference between 5.x and 6+ - no idea but I know there was a lot of work in the area and the crew was happy after they finished testing everything in #3339 - perhaps this was missed though, have you tried tracing through or instrumenting deleteToken to make sure it is called? |
@mikehardy Yes, it is called fcm api when execute |
@kratuwu that is both fortunate and unfortunate - unless there is some caching on the token in this module (does getToken() do any caching in the javascript or the objective-C in this module? I doubt it) then this indicates either an unsupported test scenario (possible but unlikely) or an upstream bug in https://github.com/firebase/firebase-ios-sdk - have you looked there? I notice you specified package.json versions at ^7.10 which should include the most up to date iOS SDK (4db9dbc) so I'm not sure where else to look if not in the underlying SDK now |
@kratuwu it appears that @dackers86 reproduces this in his (unrelated, but in the same area) work today, and points towards the underlying SDK if my understanding is correct: #3725 (comment) - have you looked upstream yet? they may have an open issue |
@mikehardy I saw this pull request firebase/firebase-ios-sdk#5339 look similar but was merged since April. |
That one looks to have shipped in SDK release 6.23.0, and you should be on 6.25.0, you can verify with Podfile.lock - might be a fresh issue 🤔 - I'm sorry I haven't been more help, you appear to have isolated the issue such that we're pretty sure you're calling APIs correctly, we're pretty we are calling the underlying APIs correctly, and I'm not much help beyond that 😞 |
Yes, my Podfile.lock SDK version is 6.25, Do you know this issue gonna fix soon? |
I know nothing about this issue, unless @dackers86 was planning on taking it up with google in the firebase-ios-sdk repository directly I think the best course of action is to make a fresh issue there, perhaps linking back to this one, asking for help. They may require an Objective-C reproduction of it using only the underlying iOS APIs directly, but if this is an issue it should be very easy to reproduce |
@mikehardy A bit of debugging on the IOS side suggests that the token that is returned after deletion is cached... if (cachedToken) { |
@dackers86 sorry to pester - where did those lines come from? with github you can do get a permalink for a code line, then shift-select to get multiple lines like The problem is these seem to reference into Instance ID and I can't seem to find source for that one. If this is really an upstream bug we should file it though I think, seems serious! @kratuwu do you get the new token if you restart the app but don't call deleteToken again? Said a different way, after a deleteToken, if it's a caching issue then an app restart should result in the new token showing up. Not ideal at all but would show it's a caching problem. |
@mikehardy I got the new token when I delete the app and install again but not get the new one if just kill and reopen it. |
@mikehardy I think this maybe an issue with the Firebase IOS SDK. This line is never called... The token that is returned appears here. https://github.com/firebase/firebase-ios-sdk/blob/dbe900774974e36332decb75d1ba842e7faa2130/Firebase/InstanceID/FIRInstanceID.m#L219 |
@kratuwu - as you are the interested parties here and it appears to be an upstream issue, the next step is for you (as a user of the upstream library too) is to open an issue upstream, with this info |
Closing issue as the problem lies within the Firebase SDK, rather than RNF |
I'm currently having the same problems with IOS. I'm using messaging().getToken() to get the token to store it in my database. After a logout, I use messaging.deleteToken() to delete the token. Sign in: messaging().getToken(): abc123 When I reload the app after signing out, still nothing happens, I still get the same token. Only after a fresh install I get a new token. Is there already a solution for this problem? |
As I was running into the same issue, and couldn't find any followup in this repo or the firebase-sdk, I took the liberty to file an issue at the firebase-sdk project. Find it here: firebase/firebase-ios-sdk#6433 |
@mtieltjes nice! You might have more response there if you stick with their native example for a repro though - they have a habit of closing things based on repros above their stack vs in their stack https://github.com/firebase/quickstart-ios/tree/master/messaging |
@mtieltjes @yesterday24 It is not clear where is the problem, on RNF or firebase-ios-sdk side. |
@golya that is champion troubleshooting! Seriously, great digging. I've asked @Salakar internally and attempted to look through firebase-js-sdk (which we pattern off of frequently, for API: https://github.com/firebase/firebase-js-sdk/) but not come up with anything. A parallel implementation that is sometimes useful for comparison is FlutterFire https://github.com/FirebaseExtended/flutterfire/blob/master/packages/firebase_messaging/lib/firebase_messaging.dart but don't have the time to dive in fully I'm going to re-open this while it's under consideration |
@mikehardy thanks for the help! It seems the FlutterFire use handler everywhere (which probably means it using the default scope): In this case I think the RNF should use the deleteIDWithHandler as well in case of deleteToken. On the other hand I have conversation with @chliangGoogle who is a contributor of firebase-ios-sdk, and I try to figure out how can you use an own scope with the cache, because based on the firebase-ios-sdk code it seems impossible, and probably I am wrong. |
Very interesting @golya - I'm listening here and I think either direction (just using handler, or fully handling scopes) seem like fine ways to go for the RNFB use case. It does seem based on your investigation that there is a problem to fix and just staying the way it is now is not correct. Please come back with whatever findings you obtain from the firebase-ios-sdk collaboration |
Since the problem is currently under consideration (i guess), as a temporary fix for anyone stuck in emergency, as suggested by @golya using deleteIDWithHandler seem to solve the problem for me.
Also, another workaround is using |
@tuan-hma excellent - note that you can (and I recommend it...) use https://github.com/ds300/patch-package to make those changes reliably + safely if you haven't seen it I haven't heard anything definitive further on this (@Salakar was sick when I asked before - maybe he has time now 🙏 ) so I'm not sure if he has an opinion on how to handle this |
@golya I re-read everything and your approach to use default scope (from here #3714 (comment)) seems fine to me in the absence of any dissent (and there has been no dissent). If you want to propose a PR to do that, I will merge it and we can move on. My only question in the PR would be to consider whether existing tokens become invalid after the change such that it means apps need to fetch new tokens on the update. I don't think they do, so my point is mostly just to consider the change impact on existing user base to make sure edit: related conversation for posterity: firebase/firebase-ios-sdk#6433 |
@mikehardy ok, if I have time I will do a pull request and yes it is possible to do the whole thing with scope (which means that is possible to do it without breaking change.) |
Any news on this? |
@Stevemoretz not yet, I can not estimate right now when will have time to finish the pull request. |
I found a workaround, passing (undefined,'*') in the function makes it work on both Android and ios. |
Inside my app I received a valid token the first time I installed / launched the app, but on subsequent launches received invalid tokens from getToken(). I had to call |
@joshallison tokens should be stable, if you get new tokens on launch you likely have some other module invalidating/requesting tokens, and in my experience based on other issues in this repo it will be maddening |
Hello 👋, to help manage issues we automatically close stale issues.
|
Just a note since this is the group of most interested parties: next version of native SDKs removed support for custom token scopes, however I tested the deleteToken/getToken path (via a check in our automated test suite here) and the new version of the SDKs seem to behave correctly. Pay attention when v12.0.0 comes out here and let us know please if this issue crops up again after removing the token scopes we're using for v11.x. Thanks! |
Confirming that deleteToken() now works properly! Thanks for everyone involved in this update. |
I was experiencing the same issue from the top of the thread, where I was unable to retreive fresh token once I execute Is this currently the correct way to achieve this behavior, or am I missing something? I have latest versions of react native at 0.73.1 and @react-native-firebase/messaging at 18.7.3 |
Issue
I need to delete token and get renew token, I try to use
messaging().deleteToken()
For Android working find but iOS still log same value of token2 and token1
Project Files
Javascript
Click To Expand
package.json
:firebase.json
for react-native-firebase v6:# N/A
iOS
Click To Expand
ios/Podfile
:AppDelegate.m
:Android
Click To Expand
Have you converted to AndroidX?
android/gradle.settings
jetifier=true
for Android compatibility?jetifier
for react-native compatibility?android/build.gradle
:// N/A
android/app/build.gradle
:// N/A
android/settings.gradle
:// N/A
MainApplication.java
:// N/A
AndroidManifest.xml
:<!-- N/A -->
Environment
Click To Expand
react-native info
output:react-native-firebase
version you're using that has this issue:e.g. 5.4.3
Firebase
module(s) you're using that has the issue:e.g. Instance ID
TypeScript
?Y/N
&VERSION
React Native Firebase
andInvertase
on Twitter for updates on the library.The text was updated successfully, but these errors were encountered: