firebase / flutterfire

🔥 A collection of Firebase plugins for Flutter apps.
https://firebase.google.com/docs/flutter/setup
BSD 3-Clause "New" or "Revised" License
8.67k stars 3.97k forks source link

[📚] FCM client for Flutter #12676

Open SamBeNuts opened 5 months ago

SamBeNuts commented 5 months ago

Hi, while onboarding my Flutter app with FCM, I noticed multiple behaviors that differ from what it's written in the documentation. Note that I only tested with iOS so things might behave differently on Android (which would be annoying as I'm expecting Flutter to act the same whatever the platform is).

To retrieve the current registration token for an app instance, call getToken(). If notification permission has not been granted, this method will ask the user for notification permissions. Otherwise, it returns a token or rejects the future due to an error. _Sources: https://firebase.google.com/docs/cloud-messaging/flutter/client#access_the_registration_token and https://firebase.google.com/docs/cloud-messaging/flutter/first-message#access_the_registration_token_

Calling getToken() never asks for permission, even on first launch when the authorizationStatus is obviously notDetermined. After checking the code nothing seems to request permission so maybe the doc is just not up-to-date.

FirebaseMessaging.instance.onTokenRefresh.listen((fcmToken) { // Note: This callback is fired at each app startup and whenever a new token is generated. }) _Source: https://firebase.google.com/docs/cloud-messaging/flutter/client#access_the_registration_token_

This callback is never called on app startup. In my opinion, it makes sense to not fire an event if token didn't change since last startup but while testing it was not even triggered on first app launch.

For apple platforms, ensure the APNS token is available before making any FCM plugin API calls _Source: https://firebase.google.com/docs/cloud-messaging/flutter/client#access_the_registration_token_

From my understanding, FCM needs to register the APNS token in order to map it to the registration token so any calls before that would fail. I think it would be better to explain that in the documentation with more details around the cases when the APNS token might be null and what to do in this situation. On the latter, would you recommend to retry with an exponential backoff?

Please have a look and update the doc accordingly.

SamBeNuts commented 4 months ago

Any updates?