当收到通知的应用程序在后台时,FirebaseMessaging.configure无法运行

时间:2019-04-13 03:13:48

标签: firebase flutter firebase-cloud-messaging

当收到通知的应用程序处于后台时,FirebaseMessaging实例的

配置方法无法运行。

class MainMenuState extends State<MainMenuPage> {
  final FirebaseMessaging _messaging = FirebaseMessaging();

  int counter = 1;

  @override
  void initState() {
    super.initState();

    _messaging.getToken().then((token){
    print(token);
  });

  _messaging.configure(

    onMessage: (Map<String, dynamic> message) async {
      print("A notification was received. But this onMessage won't run when app is in background.");
      postCall(message['notification']['title'], message['notification']['body']);
    },
    onResume: (Map<String, dynamic> message) async {
      print("onResume will run when a notification is pressed, resuming an app in background.");
      postCall(message['data']['title'], message['data']['body']);
    },
    onLaunch: (Map<String, dynamic> message) async {
      print('on launch $message');
    }
  );
}

0 个答案:

没有答案