简体   繁体   English

firebase_messaging 回调在前台时不会触发。 iOS 应用程序 Flutter

[英]firebase_messaging callbacks don't fire when in foreground . iOS app Flutter

I'm porting my Swift app to Flutter and I'm setting up the FCM using firebase_messaging package.我正在将我的 Swift 应用程序移植到 Flutter,我正在使用firebase_messaging包设置 FCM。 When using my Swift app if I send a test message from Firebase console either directly to token or broadly, and I get the notification delivered to the system tray whether the app is in foreground or in background.在使用我的 Swift 应用程序时,如果我从 Firebase 控制台直接向令牌发送测试消息或广泛发送测试消息,并且无论应用程序是在前台还是在后台,我都会收到发送到系统托盘的通知。

This doesn't happen with the Flutter app. Flutter 应用程序不会发生这种情况。 When App is in background I still get both notification in the system tray, but when in foreground none of the onMessage , onLaunch or onResume callbacks gets called.当 App 在后台时,我仍然在系统托盘中收到两个通知,但是在前台时没有onMessageonLaunchonResume回调被调用。

Can you spot what I'm doing wrong?你能看出我做错了什么吗? Many thanks.非常感谢。

class _MapScreenState extends State<MapScreen> {
  final FirebaseMessaging _firebaseMessaging = FirebaseMessaging();
  String _token;
  String _launchMessage;
  @override
  void initState() {
    super.initState();
    _firebaseMessaging.requestNotificationPermissions(
        const IosNotificationSettings(sound: true, badge: true, alert: true));

    _firebaseMessaging.onIosSettingsRegistered
        .listen((IosNotificationSettings settings) {
      print("Settings registered: $settings");
    });

    _firebaseMessaging.configure(
      onMessage: (Map<String, dynamic> message) async {
        print('on message $message');
      },
      onResume: (Map<String, dynamic> message) async {
        print('on resume $message');
      },
      onLaunch: (Map<String, dynamic> message) async {
        print('on launch $message');
      },
    );

    _firebaseMessaging.getToken().then((token) {
      print('token: $token');
      if (mounted) {
        setState(() {
          _token = token;
        });
      } else {
        _token = token;
      }
    });
  }

Ok, I found the problem being the package itself.好的,我发现问题出在包本身上。 When switching to MaikuB fork of the plugin it all works as expected.当切换到插件的 MaikuB 分支时,一切都按预期工作。

#  firebase_messaging: 6.0.9 # doesn't work

      firebase_messaging: # works properly
        git:
          url: https://github.com/MaikuB/flutterfire.git
          path: packages/firebase_messaging

He told me that this is been merged to the official repo so it's due an update of the plugin that saves this.他告诉我这已合并到官方存储库中,因此应该更新插件以保存它。 MaikuB's fork actually solves incompatibility with other plugins that need to register to MaikuB的fork其实解决了其他插件不兼容需要注册的问题

if #available(iOS 10.0, *) {
        UNUserNotificationCenter.current().delegate = self as? UNUserNotificationCenterDelegate
    }

as his own flutter_local_notification plugin , used to show local notification.作为他自己的flutter_local_notification插件,用于显示本地通知。

I hope that this can help other while a new version of the plugin is rolled out, as making it work has been quite frustrating..我希望在推出新版本的插件时这可以帮助其他人,因为让它工作非常令人沮丧..

Cheers干杯

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

相关问题 Flutter firebase_messaging iOS应用程序在前台运行时未收到上推通知 - Flutter firebase_messaging iOS app not receiving push-up notifications while app in foreground 无法使用 firebase_messaging 在 iOS 上的 Flutter 应用程序中订阅主题 - Can't subscribe to topic in a Flutter app on iOS using firebase_messaging Flutter [firebase_messaging] IOS 构建错误 - Flutter [firebase_messaging] IOS Build Error Flutter firebase_messaging - Flutter firebase_messaging Firebase_messaging onResume 和 onLaunch 回调不会在 Flutter 中调用 - Firebase_messaging onResume and onLaunch callbacks are not called in flutter Flutter firebase_messaging 6.0.9 - Flutter firebase_messaging 6.0.9 flutter 中的自定义通知,带有 firebase_messaging(Android 和 IOS) - Custom notification in flutter with firebase_messaging (Android and IOS) Flutter firebase_messaging 后台处理程序未执行但消息到达 iOS - Flutter firebase_messaging Background Handler not Executing but Messages are Arriving on iOS 使用 Flutter 包 firebase_messaging 无法在 iOS 上运行后台通知 - Background notifications not working on iOS with Flutter package firebase_messaging 为什么在 ios 中使用 flutter 中的 firebase_messaging 插件没有收到通知? - why do not getting notification in ios with firebase_messaging plugin in flutter?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM