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

fix(messaging): tokenReceived listener is not triggered #838

Closed
wants to merge 2 commits into from

Conversation

ebarooni
Copy link
Contributor

@ebarooni ebarooni commented Mar 4, 2025

Pull request checklist

Please check if your PR fulfills the following requirements:

  • The changes have been tested successfully.
  • A changeset has been created (npm run changeset).
  • I have read and followed the pull request guidelines.

Closes: #820

ebarooni added 2 commits March 4, 2025 21:54
Trigger token received on manual token generation on android.
@ebarooni ebarooni changed the title Bug/issue 820 fix(messaging): tokenReceived listener is not triggered Mar 4, 2025
@ebarooni ebarooni requested a review from robingenz March 4, 2025 21:03
Copy link

pkg-pr-new bot commented Mar 4, 2025

Open in Stackblitz

@capacitor-firebase/analytics

npm i https://pkg.pr.new/capawesome-team/capacitor-firebase/@capacitor-firebase/analytics@838

@capacitor-firebase/app

npm i https://pkg.pr.new/capawesome-team/capacitor-firebase/@capacitor-firebase/app@838

@capacitor-firebase/app-check

npm i https://pkg.pr.new/capawesome-team/capacitor-firebase/@capacitor-firebase/app-check@838

@capacitor-firebase/authentication

npm i https://pkg.pr.new/capawesome-team/capacitor-firebase/@capacitor-firebase/authentication@838

@capacitor-firebase/crashlytics

npm i https://pkg.pr.new/capawesome-team/capacitor-firebase/@capacitor-firebase/crashlytics@838

@capacitor-firebase/firestore

npm i https://pkg.pr.new/capawesome-team/capacitor-firebase/@capacitor-firebase/firestore@838

@capacitor-firebase/functions

npm i https://pkg.pr.new/capawesome-team/capacitor-firebase/@capacitor-firebase/functions@838

@capacitor-firebase/messaging

npm i https://pkg.pr.new/capawesome-team/capacitor-firebase/@capacitor-firebase/messaging@838

@capacitor-firebase/performance

npm i https://pkg.pr.new/capawesome-team/capacitor-firebase/@capacitor-firebase/performance@838

@capacitor-firebase/remote-config

npm i https://pkg.pr.new/capawesome-team/capacitor-firebase/@capacitor-firebase/remote-config@838

@capacitor-firebase/storage

npm i https://pkg.pr.new/capawesome-team/capacitor-firebase/@capacitor-firebase/storage@838

commit: 041aadc

@ebarooni
Copy link
Contributor Author

ebarooni commented Mar 5, 2025

On the web the listener is not supported. Unless we want to manually trigger it when getToken is called. On iOS the current implementation matches the docs and based on the description it gets triggered whenever there is a new token generated.

The behavior on Android is different as described here. I added the call to trigger tokenReceived when getToken is triggered to match the behavior on iOS.

@@ -133,6 +133,7 @@ public void success(String token) {
JSObject result = new JSObject();
result.put("token", token);
call.resolve(result);
handleTokenReceived(token);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's not really what I had in mind, since the listener is now called every time you get the token and not just when it has changed. This is a problem because many people use the listener to send the updated token to the server, which can now lead to an unnecessary number of requests. Let me take a quick look at it myself.

@robingenz
Copy link
Member

@ebarooni Okay, I've just had a look myself. The tokenReceived listener is called correctly on the first app start as well as when the getToken method is called after the token has been deleted. The only difference I could notice is that the tokenReceived listener is called on iOS at every app start (+ when it changes) and on Android only at the first app start (+ when it changes). We could unify this but for now I would keep the behavior of the Firebase SDKs since the latest token is always available. The only problem I found was this: #839. When was the tokenReceived listener not triggered in your case?

@ebarooni ebarooni closed this Mar 5, 2025
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

Successfully merging this pull request may close these issues.

bug(messaging): tokenReceived listener is not triggered
2 participants