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

Problem firebase messaging in new version flutter #125

Open
AminAlizadeh-Dev opened this issue Apr 29, 2021 · 2 comments
Open

Problem firebase messaging in new version flutter #125

AminAlizadeh-Dev opened this issue Apr 29, 2021 · 2 comments

Comments

@AminAlizadeh-Dev
Copy link

Hi, in the firebase messaging version: 5.4.1 To get New from firebase, we did this:
FirebaseMessaging _fcm = FirebaseMessaging ();
But in the version of firebase messaging: 9.1.3 I have problem for New from firebase

thank you for your help.

@mraslamiii
Copy link

i have same problem

@fransiskapw
Copy link

This works for me, with Firebase Messaging v10.0.3

class PushNotificationService {
  final FirebaseMessaging _fcm = FirebaseMessaging.instance;
  final NavigationService _navigationService = locator<NavigationService>();

  Future initialise() async {
    NotificationSettings settings = await _fcm.requestPermission(
      alert: true,
      announcement: false,
      badge: true,
      carPlay: false,
      criticalAlert: false,
      provisional: false,
      sound: true,
    );

    if (settings.authorizationStatus == AuthorizationStatus.authorized) {
      print('User granted permission');
    } else if (settings.authorizationStatus ==
        AuthorizationStatus.provisional) {
      print('User granted provisional permission');
    } else {
      print('User declined or has not accepted permission');
    }

    // workaround for onLaunch: When the app is completely closed (not in the background) and opened directly from the push notification
    _fcm.getInitialMessage().then((RemoteMessage message) {
      print('getInitialMessage data: ${message.data}');
      _serialiseAndNavigate(message);
    });

    // onMessage: When the app is open and it receives a push notification
    FirebaseMessaging.onMessage.listen((RemoteMessage message) {
      print("onMessage data: ${message.data}");
    });

    // replacement for onResume: When the app is in the background and opened directly from the push notification.
    FirebaseMessaging.onMessageOpenedApp.listen((RemoteMessage message) {
      print('onMessageOpenedApp data: ${message.data}');
      _serialiseAndNavigate(message);
    });
  }

  void _serialiseAndNavigate(RemoteMessage message) {
  ...
  }
}

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