繁体   English   中英

Flutter - 当应用程序在后台时调用 Firebase onMessage 方法

[英]Flutter - Call Firebase onMessage method when the app is in background

当应用程序在 flutter 的后台时,问题与此处的 Call onMessage 方法相同,我正在关注该线程,但由于没有响应,我再次问这个问题。

我已将我的 Flutter 应用程序与Firebase 消息连接,当我的应用程序位于前台时,我使用Flutter 本地通知插件收到通知 但是当我的应用程序处于后台时,我无法收到任何通知

以下是我的代码:

// FIREBASE CONFIGURATION & HANDLING
_firebaseMessaging.configure(
  onMessage: (Map<String, dynamic> message) async {
    debugPrint("onMessage: $message");
    final notification = message['data']['notification'];

    Map responseBody = convert.jsonDecode(notification);

    _showNotification(
      icon: responseBody['icon'],
      title: responseBody['title'],
      body: responseBody['body'],
    );

    setState(() {});
  },
);


// DISPLAY NOTIFICATION - HEADS UP
Future<void> _showNotification({String icon, String title, String body}) async {
  var androidPlatformChannelSpecifics = AndroidNotificationDetails(
    'your channel id',
    'your channel name',
    'your channel description',
    importance: Importance.Max,
    priority: Priority.High,
    ticker: 'ticker',
  );

  var iOSPlatformChannelSpecifics = IOSNotificationDetails();

  var platformChannelSpecifics = NotificationDetails(
      androidPlatformChannelSpecifics, iOSPlatformChannelSpecifics);

  await flutterLocalNotificationsPlugin.show(
    0,
    title,
    body,
    platformChannelSpecifics,
  );
}

有人可以指导我如何在我的应用程序处于后台时接收通知

解决!!

问题在于 curl 调用的格式。 根据此处给出的说明

改变了这个:

{
  "data": {
    "notification": {
        "title": "Notification Title",
        "body": "Notification Body",
    },
        "click_action": "FLUTTER_NOTIFICATION_CLICK"
  },
  "to": "YOUR_DEVICE_TOKEN"
}

对此:

{
  "data": {
    "click_action": "FLUTTER_NOTIFICATION_CLICK",
    "id": "1",
    "status": "done",
  },
  "notification": {
    "body": "Notification Body",
    "title": "Notification Title"
  },
  "priority": "high",
  "to": "YOUR_DEVICE_TOKEN"
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM