iOS 下的 Firebase 消息传递问题

Firebase messaging problems under iOS

请查看下面的新发现

尽管遵循了 Firebase_messaging 文档中的配置步骤,但我无法让 FCM 在 iOS 上正常工作。

DATA 消息按预期工作。通知消息根本不显示,无论应用程序是在前台还是后台。

Android 通知按预期工作。此问题仅出现在 iOS 上,并且仅适用于通知消息。

我正在物理设备 (iPhone SE) 上进行测试,即使使用 TestFlight 部署应用程序,我仍然遇到同样的问题。

void configureFirebase(prefs) async {
  try {
    await _firebaseMessaging.requestNotificationPermissions();
    _firebaseMessaging.configure(
      onMessage: (Map<String, dynamic> message) async {
        print(message);
        onMessage(message);
      },
      //  onBackgroundMessage: myBackgroundMessageHandler,
      onLaunch: (Map<String, dynamic> message) async {
        print("onLaunch: $message");
        onMessage(message);
      },
      onResume: (Map<String, dynamic> message) async {
        print("onResume: $message");
        onMessage(message);
      },
    );
  } catch (e) {
    print(e);
  }
}

应用程序编译后,我得到以下信息:

2020-02-09 11:39:34.414043+0100 Runner[236:3651] Configuring the default Firebase app...
2020-02-09 11:39:34.439940+0100 Runner[236:3782] 6.16.0 - [Firebase/Core][I-COR000004] App with name __FIRAPP_DEFAULT does not exist.
2020-02-09 11:39:34.462336+0100 Runner[236:3651] Configured the default Firebase app __FIRAPP_DEFAULT.
2020-02-09 11:39:34.509495+0100 Runner[236:3797] flutter: Observatory listening on http://127.0.0.1:49413/sW_P16TvXjA=/
2020-02-09 11:39:34.530782+0100 Runner[236:3782] 6.16.0 - [Firebase/Messaging][I-FCM001000] FIRMessaging Remote Notifications proxy enabled, will swizzle remote notification receiver handlers. If you'd prefer to manually integrate Firebase Messaging, add "FirebaseAppDelegateProxyEnabled" to your Info.plist, and set it to NO. Follow the instructions at:
https://firebase.google.com/docs/cloud-messaging/ios/client#method_swizzling_in_firebase_messaging
to ensure proper integration.
2020-02-09 11:39:34.535881+0100 Runner[236:3783] 6.16.0 - [Firebase/Analytics][I-ACS023007] Analytics v.60202000 started
2020-02-09 11:39:34.536403+0100 Runner[236:3783] 6.16.0 - [Firebase/Analytics][I-ACS023008] To enable debug logging set the following application argument: -FIRAnalyticsDebugEnabled (see https://help.apple.com/xcode/mac/8.0/#/dev3ec8a1cb4)
2020-02-09 11:39:34.562674+0100 Runner[236:3783] 6.16.0 - [Firebase/Analytics][I-ACS031025] Analytics screen reporting is enabled. Call +[FIRAnalytics setScreenName:setScreenClass:] to set the screen name or override the default screen class name. To disable screen reporting, set the flag FirebaseScreenReportingEnabled to NO (boolean) in the Info.plist
2020-02-09 11:39:34.567991+0100 Runner[236:3782] 6.16.0 - [Firebase/Analytics][I-ACS023012] Analytics collection enabled

如果我在 info.plist 中禁用 FirebaseAppDelegateProxyEnabled,下面是堆栈:

2020-02-09 12:23:03.053017+0100 Runner[290:10393] Configuring the default Firebase app...
2020-02-09 12:23:03.054198+0100 Runner[290:10584] 6.16.0 - [Firebase/Core][I-COR000004] App with name __FIRAPP_DEFAULT does not exist.
2020-02-09 12:23:03.099604+0100 Runner[290:10393] Configured the default Firebase app __FIRAPP_DEFAULT.
2020-02-09 12:23:03.142294+0100 Runner[290:10596] flutter: Observatory listening on http://127.0.0.1:49543/dD-x0XTr2qQ=/
2020-02-09 12:23:03.151748+0100 Runner[290:10583] 6.16.0 - [Firebase/Analytics][I-ACS023007] Analytics v.60202000 started
2020-02-09 12:23:03.152298+0100 Runner[290:10583] 6.16.0 - [Firebase/Analytics][I-ACS023008] To enable debug logging set the following application argument: -FIRAnalyticsDebugEnabled (see https://help.apple.com/xcode/mac/8.0/#/dev3ec8a1cb4)
2020-02-09 12:23:03.153920+0100 Runner[290:10599] 6.16.0 - [Firebase/Analytics][I-ACS025036] App Delegate Proxy is disabled
2020-02-09 12:23:03.166991+0100 Runner[290:10599] 6.16.0 - [Firebase/Analytics][I-ACS031025] Analytics screen reporting is enabled. Call +[FIRAnalytics setScreenName:setScreenClass:] to set the screen name or override the default screen class name. To disable screen reporting, set the flag FirebaseScreenReportingEnabled to NO (boolean) in the Info.plist
2020-02-09 12:23:03.172381+0100 Runner[290:10580] 6.16.0 - [Firebase/Analytics][I-ACS023012] Analytics collection enabled

知道这里会发生什么吗?这是一个非常奇怪的行为,我什至不知道从哪里开始调试。

任何有关潜在解决方案的帮助或线索都将不胜感激。


添加 PyFCM 中使用的消息配置以防万一这是问题的根源:

push_service = FCMNotification(api_key=fcmServerKey)

testDATA = {
  'title': 'Test title',
  'body': 'Test body',
  'click_action': 'FLUTTER_NOTIFICATION_CLICK',
  'otherFields': 'Other fields here',
}

result = push_service.notify_single_device(
  registration_id = token,
  message_title='Test title',
  message_body='Test body',
  data_message = testDATA,
  time_to_live=0,
  delay_while_idle=False,
  extra_notification_kwargs=extraKWARGS,
  content_available=True  
)

新发现:

iOS 模拟器收到通知。但是,它们仅在应用程序位于前台时才会显示。推送通知不起作用。但是,我读到推送通知在 iOS 模拟器上不起作用,所以这可能就是原因。

考虑到我没有明显的错误,并且已经调试了大约 30 个小时但仍无济于事,我的通知问题有多大可能与这台物理设备无关(iPhone SE在我身上)可能是由于 FCM 认为它离线或它的注册 ID 无效?

我没有其他 iPhone 可以测试。

该应用程序功能齐全,并且在所有其他方面都已准备就绪...我是否应该将此视为孤立案例并提交我的应用程序?

我终于解决了这个问题。

我正在 运行ning firebase_messaging 6.0.9 和 Flutter 1.12.13+8,在 iPhone SE 上使用 iOS 13 的 MacOS Catalina。

让我们先解决一件事:firebase_messaging 在 iOS 上的行为有问题。

我基本上做的是:

1) 清理代码并确保 FCM 实现与文档完全一致。

2) 单独拥有 FCM 权限 运行,没有同时发生任何其他权限

3) 继续创建新项目并复制其中的库,直到其中一个可用[*]

是的,现在可以了。一个不令人满意的解决方案,但仍然是一个解决方案。

[*] 一旦我确定代码几乎没有失败的原因,FCM 仍然没有 运行ning。我尽我所能清理项目和 Flutter 包;然而 FCM 没有 运行 iOS。所以我创建了另一个项目,并将我的代码复制到其中。然后我开始遇到我从未设法解决的不同错误。所以我一直在创建新项目,每个项目都会导致一个新的、奇特的、无法解决的错误,我会花几个小时来调试它;有时未检测到 getToken,有时令牌为空;其他时候未检测到 requestNotifications; others firebase_messaging was not detected...等。然后其中一个安装工作​​。现在通知似乎在 iOS.

上按预期工作

编辑:

在对代码进行了一些更改并重新编译后,它又回到了不工作的状态(即使我没有对 FCM 模块或 XCode 脚本进行任何更改)。

这次重置 iPhone 修复了它。 运行 这在生产中将是一场噩梦。