gpt4 book ai didi

ios - Flutter Firebase 回调不会在 iOS 13 上触发,但在 Android 上可以正常工作

转载 作者:行者123 更新时间:2023-12-01 16:21:18 25 4
gpt4 key购买 nike

当我遇到以下情况时,我目前正在开发一个 flutter 应用程序:

在 Android 上,一切都按预期工作。如果应用程序在前台,onMessage被称为,onLaunch如果应用程序在后台,依此类推。

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

这是我发送的有效载荷:

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

flutter 代码:

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(beta channel ),但是我也尝试使用 flutter stable 运行应用程序,这导致了相同的行为。
[✓] 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 上的指南是错误的。
检查 2 件事。

  • 删除代码

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


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

    https://github.com/FirebaseExtended/flutterfire/issues/1041
    请为这个问题点赞。

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

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com