在Flutter中未调用onResume和onLaunch firebase_messaging 6.0.13

时间:2020-05-03 19:22:49

标签: android api flutter firebase-cloud-messaging

我在flutter项目中实现了firebase_messaging 6.0.13插件。 onMessage工作正常,但未调用onResume和onLaunch。以下是我的插件配置代码

_firebaseMessaging.configure(
  onMessage: (Map<String, dynamic> message) async {
    print("onMessage: $message");

  },
  onBackgroundMessage: myBackgroundMessageHandler,
  onLaunch: (Map<String, dynamic> message) async {
    print("onLaunch: $message");

  },
  onResume: (Map<String, dynamic> message) async {
    print("onResume: $message");

  },
);
_firebaseMessaging.requestNotificationPermissions(
    IosNotificationSettings(sound: true, badge: true, alert: true));
_firebaseMessaging.getToken().then((token) {
       print(token);
}); 

以下是myBackgroundMessageHandler

Future<dynamic> myBackgroundMessageHandler(Map<String, dynamic> message) {
  if (message.containsKey('data')) {
    // Handle data message
    final dynamic data = message['data'];
  }

  if (message.containsKey('notification')) {
    // Handle notification message
    final dynamic notification = message['notification'];
  }

  // Or do other work.
}

以下是我从api发送的有效负载。

var payload = new
            {
                to = "fD637iNwLqA:APA91bEtxdMTNC805-9-pYONFedGSPakpf_KcCNFrzAlS6D229NC1ubb7vwDMtR1NG2vKc9tHeNrN50BVmy-Q6tlvO35OwFbaIPt2s_PO7cF-qGmgMwUr-A5F2R_eKxz2XCPE4jtal_B",
                priority = "high",
                content_available = true,
                notification = new
                {
                    body = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc porta tempor congue. Mauris interdum enim a convallis pulvinar. Nullam pharetra ipsum non nulla tristique commodo. In non sem vel nisi sollicitudin tincidunt. Sed non convallis ligula, fermentum placerat risus. Cras a tellus in eros viverra ornare.",
                    title = "Neque porro quisquam est ",
                    badge = 1
                },
                data = new
                {
                    body = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc porta tempor congue. Mauris interdum enim a convallis pulvinar. Nullam pharetra ipsum non nulla tristique commodo. In non sem vel nisi sollicitudin tincidunt. Sed non convallis ligula, fermentum placerat risus. Cras a tellus in eros viverra ornare.",
                    title = "Neque porro quisquam est ",
                    click_action = "FLUTTER_NOTIFICATION_CLICK",
                    id = "1",
                    status = "01 May 2020",
                    image = "https://ibin.co/2t1lLdpfS06F.png",

                }

            };

我已经咨询了几乎所有的在线论坛,但是它仍然对我不起作用。

0 个答案:

没有答案