遇到以下情况时,我正在开发一款Flutter应用程序:

在Android上,一切正常。如果应用程序在前台,则调用onMessage,如果应用程序在后台,则调用onLaunch,依此类推。

在iOS(13)上,没有调用任何回调。当我单击该应用程序打开的通知时,通知到达,并显示正确的图标,文本和标题,但未触发任何回调。如果应用程序已经在前台,则不会显示任何通知(按预期方式),但也不会调用onMessage

这是我要发送的有效负载:

{
  "data": {
    "click_action": "FLUTTER_NOTIFICATION_CLICK",
    "key1": "value1"
  },
  "to": "RECEIVER",
  "notification": {
    "sound": "default",
    "title": "Title",
    "body": "Message"
  }
}

颤振代码:

firebaseMessaging.configure(
  onMessage: (Map<String, dynamic> message) {
    log.info('Firebase::onMessage: $message');

    _handleMessage(message);
  },
  onResume: (Map<String, dynamic> message) {
    log.info('Firebase::onResume: $message');

    _handleMessage(message);
  },
  onLaunch: (Map<String, dynamic> message) {
    log.info('Firebase::onLaunch: $message');

    _handleMessage(message);
  },
);

AppDelegate.swift:

我尝试使用以下行运行应用程序

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

我已在XCode的功能选项卡中启用了推送通知,后台获取和远程通知。

我正在运行Flutter 1.12.13(测试版通道),但是我也尝试使用稳定的flutter运行该应用程序,这导致了相同的行为。
[✓] Flutter (Channel beta, v1.12.13+hotfix.3, on Mac OS X 10.15.1 19B88, locale en-DE)
    • Flutter version 1.12.13+hotfix.3 at /usr/local/bin/flutter
    • Framework revision 57f2df76d7 (3 days ago), 2019-12-05 21:23:21 -0800
    • Engine revision ac9391978e
    • Dart version 2.7.0

[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
    • Android SDK at /Users/martin/Library/Android/sdk
    • Android NDK location not configured (optional; useful for native profiling support)
    • Platform android-29, build-tools 29.0.2
    • Java binary at: /Users/martin/Library/Application Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/191.6010548/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b49-5587405)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 11.2.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 11.2.1, Build version 11B500
    • CocoaPods version 1.8.4

[✓] Android Studio (version 3.5)
    • Android Studio at /Users/martin/Library/Application Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/191.6010548/Android Studio.app/Contents
    • Flutter plugin version 40.0.2
    • Dart plugin version 191.8423
    • Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b49-5587405)

[!] IntelliJ IDEA Ultimate Edition (version 2019.3)
    • IntelliJ at /Users/martin/Applications/JetBrains Toolbox/IntelliJ IDEA Ultimate.app
    ✗ Flutter plugin not installed; this adds Flutter specific functionality.
    ✗ Dart plugin not installed; this adds Dart specific functionality.
    • For information about installing plugins, see
      https://flutter.dev/intellij-setup/#installing-the-plugins

[!] Connected device
    ! No devices available

! Doctor found issues in 2 categories.

提前致谢!

最佳答案

编辑:
使用ios 13,Readme.md上的指南错误。
检查两件事。

  • 删除代码

    if (@available(iOS 10.0, *)) {
    [UNUserNotificationCenter currentNotificationCenter].delegate = (id) self;
    }
    
  • 检查您是否具有“flutter_local_notifications”库
    然后,将其删除。


  • 目前,我知道这是由iOS 13更新引起的插件错误。

    https://github.com/FirebaseExtended/flutterfire/issues/1041
    请竖起大拇指解决此问题。

    关于ios - 在iOS 13上不会触发Flutter Firebase回调,但在Android上可以正常使用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/59253265/

    10-16 14:05