接收方FCM通知点击事件

时间:2019-04-09 19:55:46

标签: firebase dart flutter firebase-cloud-messaging flutter-dependencies

如何在Flutter上收到通知点击事件?

我在main.dart上编写了这段代码,但是onMessage处理事件不起作用。

此代码块也无法在后台运行。

当在后台运行onMessage函数的应用无法处理时。

main.dart

    FirebaseMessaging _firebaseMessaging = FirebaseMessaging();
void iOS_Permission() {
  _firebaseMessaging.requestNotificationPermissions(
      IosNotificationSettings(sound: true, badge: true, alert: true)
  );
  _firebaseMessaging.onIosSettingsRegistered
      .listen((IosNotificationSettings settings)
  {
    print("Settings registered: $settings");
  });
}
void firebaseCloudMessaging_Listeners(BuildContext context) {
  if (Platform.isIOS) iOS_Permission();

  _firebaseMessaging.getToken().then((token){
    print("Token : ${token}");
  });

  _firebaseMessaging.configure(
    onMessage: (Map<String, dynamic> message) async {
      print('on message $message');
    },
    onResume: (Map<String, dynamic> message) async {
      print('on resume $message');
    },
    onLaunch: (Map<String, dynamic> message) async {
      Navigator.pushNamed(context, "/");
      print('on launch $message');
    },
  );
}
void main() {
  print("uygulama Acildi");
  debugPaintSizeEnabled = false;
  runApp(MaterialApp(
    localizationsDelegates: [
    GlobalMaterialLocalizations.delegate,
    GlobalWidgetsLocalizations.delegate,
  ],supportedLocales: [
    const Locale('tr', 'TR'),
  ],
    theme: ThemeData(fontFamily: 'Oswald'),
    initialRoute: '/',
    routes: <String, WidgetBuilder>{
     // '/': (context) => SanalPulHareketleri(),
      '/': (context) => SplashEkrani(),
      '/kayit_ol': (context) => KayitOl(),
    },
  ));
}

1 个答案:

答案 0 :(得分:0)

onMessage 在您收到通知并且Foreground中的App正在运行时被触发。

请查看 onResume onLaunch 回调。 您可以找到on the library page

的更多信息