iOS 在 Flutter 中终止应用程序后第一次通知时不调用 _firebaseMessagingBackgroundHandler

问题描述 投票:0回答:1

我正在开发一个 Flutter 项目,其中使用 Firebase Cloud Messaging (FCM) 接收推送通知并在应用程序中显示它们。在 Android 上一切都按预期运行。然而,在 iOS 上,我遇到了一个特殊的问题:

应用完全终止后(不是在后台),设备收到第一个推送通知,应用被唤醒,但 _firebaseMessagingBackgroundHandler 不会被调用。仅当应用程序完全关闭后收到的第一个通知时,才会出现此问题。后续通知工作正常,并且 _firebaseMessagingBackgroundHandler 按预期调用。

这是我的设置的简要概述:

颤振版本:3.3.1 firebase_core:^1.24.0 firebase_analytics:^9.3.8 firebase_消息传递:^13.1.0 firebase_crashlytics:^2.9.0 我已确认 FCM 的负载配置正确,并且内容可用标志设置为 1。我的 Info.plist 还配置了后台获取和通知所需的权限。

我想知道第一个通知是否存在已知问题或限制,无法在完全终止的 iOS 应用程序上触发 _firebaseMessagingBackgroundHandler,或者是否存在我可能缺少的任何其他配置。

任何见解或建议将不胜感激!

@pragma('vm:entry-point')
Future<void> _firebaseMessagingBackgroundHandler(RemoteMessage message) async {
  debugPrint('[background msg]'); // didn't show
  await Firebase.initializeApp(
    name: 'myProject',
    options: DefaultFirebaseOptions.currentPlatform,
  );
  debugPrint('[background msg]'); // didn't show
}

我看到ios设备在xcode控制台中收到apns消息。但 _firebaseMessagingBackgroundHandler 在第一次推送通知期间不会被调用。

ios flutter firebase firebase-cloud-messaging push
1个回答
0
投票

我找到了解决方案。

移动此代码

'FirebaseMessaging.onBackgroundMessage(backgroundMessageHandler);'

到前面的 main 方法。仅此而已...

https://github.com/firebase/flutterfire/issues/11500

© www.soinside.com 2019 - 2024. All rights reserved.