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

🐛 [firebase_messaging] onRefreshToken doesn't invoke when the app opens for the first time. #10043

Closed
iLoveDocs opened this issue Dec 2, 2022 · 4 comments · Fixed by #11447
Labels
platform: android Issues / PRs which are specifically for Android. plugin: messaging resolution: fixed A fix has been merged or is pending merge from a PR. type: bug Something isn't working

Comments

@iLoveDocs
Copy link
Contributor

iLoveDocs commented Dec 2, 2022

Bug report

When the app is opened for the first time, the onRefreshToken callback doesn't get called.

Steps to reproduce

Uninstall the app (if it is already installed) and run the following code.
The print statement doesn't print the token.

void main() async {
  WidgetsFlutterBinding.ensureInitialized();

  await Firebase.initializeApp(
    options: DefaultFirebaseOptions.currentPlatform,
  );

  FirebaseMessaging.instance.onTokenRefresh.listen((token) {
    print('token = $token'); // Doesn't print
  });

  runApp(...);
}

Expected behavior

The onRefreshToken should fire when the app opens (launches) for the first time.

Version:

firebase_messaging: ^14.0.3

Additional context:

I have this code in a java file and this does print the new token:

public class MessagingService extends FirebaseMessagingService {
    @Override
    public void onNewToken(@NonNull String s) {
        super.onNewToken(s);
        Log.i("Tag", "New FCM token = " + s);
    }
}
@iLoveDocs iLoveDocs added Needs Attention This issue needs maintainer attention. type: bug Something isn't working labels Dec 2, 2022
@darshankawar darshankawar added the triage Issue is currently being triaged. label Dec 5, 2022
@darshankawar
Copy link

@iLoveDocs
On what platform are you seeing this behavior ?
Can you also provide flutter doctor -v and verify the same using latest plugin version ?

@darshankawar darshankawar added blocked: customer-response Waiting for customer response, e.g. more information was requested. and removed Needs Attention This issue needs maintainer attention. labels Dec 5, 2022
@iLoveDocs
Copy link
Contributor Author

@darshankawar

On what platform are you seeing this behavior ?

Android.

Can you also provide flutter doctor -v and verify the same using latest plugin version ?

Yes, the latest plugin version 14.1.3 also has this same issue. Wouldn't it be better if you run the min reproducible code (and I hope this is why we need to provide it) on your end and confirm whether or not you also see this issue. This will make things go faster.

[✓] Flutter (Channel master, 3.6.0-9.0.pre.2, on macOS 12.6 21G115 darwin-arm64, locale en-US)
    • Flutter version 3.6.0-9.0.pre.2 on channel master at <some_path>
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 2703a2bcde (10 days ago), 2022-11-28 07:41:07 +0100
    • Engine revision 7665ae5184
    • Dart version 2.19.0 (build 2.19.0-429.0.dev)
    • DevTools version 2.19.0

[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
    • Android SDK at <some_path>
    • Platform android-33, build-tools 33.0.0
    • Java binary at: <some_path>
    • Java version OpenJDK Runtime Environment (build 11.0.13+0-b1751.21-8125866)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 14.0.1)
    • Xcode at <some_path>
    • Build 14A400
    • CocoaPods version 1.11.2

[✓] Chrome - develop for the web
    • Chrome at <some_path>

[✓] Android Studio (version 2021.3)
    • Android Studio at <some_path>
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.13+0-b1751.21-8125866)

[✓] IntelliJ IDEA Community Edition (version 2022.3)
    • IntelliJ at <some_path>
    • Flutter plugin version 71.0.6
    • Dart plugin version 223.7571.203

[✓] VS Code (version 1.73.1)
    • VS Code at <some_path>
    • Flutter extension can be installed from:
      🔨 https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter

[✓] Connected device (3 available)
    • Android SDK built for arm64 (mobile) • emulator-5554 • android-arm64  • Android 10 (API 29) (emulator)
    • macOS (desktop)                      • macos         • darwin-arm64   • macOS 12.6 21G115 darwin-arm64
    • Chrome (web)                         • chrome        • web-javascript • Google Chrome 108.0.5359.94

[✓] HTTP Host Availability
    • All required HTTP hosts are available

@google-oss-bot google-oss-bot added Needs Attention This issue needs maintainer attention. and removed blocked: customer-response Waiting for customer response, e.g. more information was requested. labels Dec 7, 2022
@darshankawar
Copy link

Thanks for the update. Keeping this issue open and labeling based on the report.

@darshankawar darshankawar added plugin: messaging platform: android Issues / PRs which are specifically for Android. and removed Needs Attention This issue needs maintainer attention. triage Issue is currently being triaged. labels Dec 9, 2022
@MichealReed
Copy link

Also seeing this on firebase_messaging: ^14.5.0 platform web. I have to use getToken on each run and update the token in my db as it is different than the previous.

@darshankawar darshankawar added the resolution: fixed A fix has been merged or is pending merge from a PR. label Aug 16, 2023
@firebase firebase locked and limited conversation to collaborators Sep 15, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
platform: android Issues / PRs which are specifically for Android. plugin: messaging resolution: fixed A fix has been merged or is pending merge from a PR. type: bug Something isn't working
Projects
None yet
4 participants