Flutter 背景 iOS 通知在 XCode 或 TestFlight 中不起作用
Posted
技术标签:
【中文标题】Flutter 背景 iOS 通知在 XCode 或 TestFlight 中不起作用【英文标题】:Flutter background iOS notification don't work in XCode or TestFlight 【发布时间】:2020-09-05 07:22:46 【问题描述】:我正在尝试使用 Flutter 在 ios 设备上接收后台推送通知。我已经设法让它在 android 上运行,如果我使用 Android Studio 运行代码,它也适用于 iOS 调试,但是当我使用 XCode 运行代码时,我无法获得后台通知,我得到了这个:
2020-05-19 01:45:43.617423-0700 Runner[924:720398] dnssd_clientstub read_all(22) DEFUNCT
2020-05-19 01:45:43.618224-0700 Runner[924:720398] [VERBOSE-2:FlutterObservatoryPublisher.mm(131)] 无法注册为 FlutterObservatoryPublisher 的服务器。检查您的网络设置并重新启动应用程序。
2020-05-19 01:45:43.657713-0700 Runner[924:720653] [] nw_read_request_report [C1] 接收失败,出现错误“软件导致连接中止”
2020-05-19 01:45:43.661093-0700 Runner[924:720653] [] nw_read_request_report [C1] 接收失败,出现错误“软件导致连接中止”
通知在 TestFlight 中也不起作用。 你能帮帮我吗?
现在我正在使用
firebase_messaging: ^6.0.15
但在以前的版本中,我遇到了同样的情况。
我的颤振医生--verbose:
[✓] Flutter (Channel stable, v1.17.0, on Mac OS X 10.15.4 19E287, locale it-IT)
• Flutter version 1.17.0 at /Users/xxxxx/development/flutter
• Framework revision e6b34c2b5c (2 settimane fa), 2020-05-02 11:39:18 -0700
• Engine revision 540786dd51
• Dart version 2.8.1
[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.3)
• Android SDK at /Users/xxxxx/Library/Android/sdk
• Platform android-29, build-tools 29.0.3
• Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b4-5784211)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS (Xcode 11.4.1)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Xcode 11.4.1, Build version 11E503a
• CocoaPods version 1.9.1
[✓] Android Studio (version 3.6)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin version 45.1.1
• Dart plugin version 192.7761
• Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b4-5784211)
[✓] VS Code (version 1.44.2)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.10.1
[✓] Connected device (1 available)
• iPhone • ios • iOS 13.4.1
【问题讨论】:
【参考方案1】:像这样更改您的 appDelegate :
import UIKit
import Flutter
@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool
if #available(iOS 10.0, *)
UNUserNotificationCenter.current().delegate = self as? UNUserNotificationCenterDelegate
GeneratedPluginRegistrant.register(with: self)
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
override func applicationDidBecomeActive(_ application: UIApplication)
signal(SIGPIPE, SIG_IGN);
override func applicationWillEnterForeground(_ application: UIApplication)
signal(SIGPIPE, SIG_IGN);
【讨论】:
以上是关于Flutter 背景 iOS 通知在 XCode 或 TestFlight 中不起作用的主要内容,如果未能解决你的问题,请参考以下文章