firebase-messaging - 致命:找不到回调 [英] firebase-messaging - Fatal: failed to find callback

查看:22
本文介绍了firebase-messaging - 致命:找不到回调的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 FCM 消息传递并不断收到此错误.

I'm trying to use FCM messaging and keep getting this error.

E/FlutterFcmService(3684):致命:找不到回调

下面是我用来设置的代码.

Below is the code I've used to setup.

  static Future<void> messagePiper(
      Map<String, dynamic> message,
      FilteredMap<String, ChatMessage> globalChatEntryMap,
      FilteredMap<String, ChatMessage> gameChatEntryMap,
      Subject<List<ChatMessage>> globalChatSubject,
      Subject<List<ChatMessage>> gameChatSubject,
      Map<String, Player> _playerMap) async {
    final Map<String, dynamic> data = message['data'];
    if (data.containsKey('name')) {
      final msg = ChatMessage.fromMap(data);
      globalChatEntryMap.putIfAbsent(msg.id, () => msg);
      globalChatSubject.add(globalChatEntryMap.values.toList());
    } else {
      final msg = GameChatMessage.fromMap(data);

      final chat = ChatMessage.fromGlobalChatMessage(
        msg,
        _playerMap[msg.pId].name,
        _playerMap[msg.pId].imageUrl,
      );

      print('chat: $chat');
      gameChatEntryMap.putIfAbsent(msg.id, () => chat);
      print('_gameChatEntryMap : $gameChatEntryMap');
      gameChatSubject.add(gameChatEntryMap.values.toList());
    }

    return Future<void>.value();
  }

是传入 FirebaseMessaging 配置的回调.

is the callback passed in to FirebaseMessaging configuration.

  final FirebaseMessaging _fm = FirebaseMessaging();

  @override
  void initState() {

   _fm.configure(
        onMessage: (Map<String, dynamic> message) async {
          print('onMessagee : $message');
          return Utils.messagePiper(
              message,
              _globalChatEntryMap,
              _gameChatEntryMap,
              _globalChatSubject,
              _gameChatSubject,
              _playerMap);
        },
        onLaunch: (Map<String, dynamic> message) async {
          print('onLaunch : $message');
          return Utils.messagePiper(
              message,
              _globalChatEntryMap,
              _gameChatEntryMap,
              _globalChatSubject,
              _gameChatSubject,
              _playerMap);
          ;
        },
        onResume: (Map<String, dynamic> message) async {
          print('onResume : $message');
          return Utils.messagePiper(
              message,
              _globalChatEntryMap,
              _gameChatEntryMap,
              _globalChatSubject,
              _gameChatSubject,
              _playerMap);
          ;
        },
        onBackgroundMessage: null);
....

Java 配置文件

package io.flutter.plugins;

import io.flutter.app.FlutterApplication;
import io.flutter.plugin.common.PluginRegistry;
import io.flutter.plugin.common.PluginRegistry.PluginRegistrantCallback;
import io.flutter.plugins.GeneratedPluginRegistrant;
import io.flutter.plugins.firebasemessaging.FlutterFirebaseMessagingService;

public class Application extends FlutterApplication implements PluginRegistrantCallback {
    @Override
    public void onCreate() {
        super.onCreate();
        FlutterFirebaseMessagingService.setPluginRegistrant(this);
    }

    @Override
    public void registerWith(PluginRegistry registry) {
        GeneratedPluginRegistrant.registerWith(registry);
    }
}

依赖版本

  random_string: 0.0.2
  firebase_auth: ^0.14.0+5
  firebase_database: ^3.0.7
  provider: 3.0.0
  rxdart: ^0.22.2
  collection: ^1.14.11
  audioplayers: ^0.13.2
  firebase_admob: ^0.5.5
  connectivity: ^0.4.4
  firebase_messaging: ^5.1.6 # tried with several different versions

我尝试了几个 firebase_messaging 版本,但找不到修复方法.

I tried with several firebase_messaging versions but couldn't find a fix.

感谢任何帮助解决此问题.

Appreciate any help to solve this issue.

推荐答案

此错误消息来自 startBackgroundIsolate 用于允许处理后台消息.如果您不想处理后台消息,那么您可以放心地忽略此错误消息.否则,您需要按照此处

This error message is coming from startBackgroundIsolate which is used for allowing handling background messages. If you don't want to handle background messages then you can safely ignore this error message. Otherwise, you need to set up a callback for handling background messages as described here

如果点击通知时没有执行回调,那是因为您没有将消息的 click_action 属性设置为 FLUTTER_NOTIFICATION_CLICK

If your callback is not executed when clicking on the notification then it's because you didn't set click_action property of the message to FLUTTER_NOTIFICATION_CLICK

这篇关于firebase-messaging - 致命:找不到回调的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆