如何获取Firebase通知数据?

时间:2020-04-15 20:28:50

标签: firebase flutter dart

像这样在应用中时,我可以在onMessage中收到Firebase消息:

{data: {}, notification: {body: how are you , title: hi}}

我在initState中的代码:

    firebaseMessaging.configure(

    onLaunch: (Map<String,dynamic> msg){
      print(" onLaunch called");
      print(msg);
    },
    onResume: (Map<String,dynamic> msg){
      print(" onResume called");
      print(msg);

    },
    onMessage: (Map<String,dynamic> msg){
      print(" onMessage called");
      print(msg);
      setState(() {
        sms=msg['notification']['body'];
      });
    },


    );
     firebaseMessaging.requestNotificationPermissions(
      const IosNotificationSettings(
          sound: true,
          alert: true,
          badge: true
      )
    );
      firebaseMessaging.onIosSettingsRegistered.listen((IosNotificationSettings setting){
       print("ios setting registed");
    });
      firebaseMessaging.getToken().then((token){
       update(token);
    });
    }
     update(String token){
       print(token);
        setState(() {
         textValue=token;
     });

我想在后台或关闭应用程序时收到Firebase消息, 我该怎么办?

1 个答案:

答案 0 :(得分:1)

您需要了解的所有信息都在Firebase Messaging软件包的Receiving Message部分中进行了说明。

仅当用户单击通知时,方法onResumeonLaunch会被触发