ios - Flutter 背景 iOS 通知在 XCode 或 TestFlight 中不起作用
问题描述
我正在尝试使用 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
,但在以前的版本中,我遇到了同样的情况。
我的颤振医生——详细:
[✓] 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
解决方案
像这样更改您的 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);
}
}
推荐阅读
- javascript - JavaScript - 推送数组的索引
- sql - 面临 3 个表的 SQL 查询问题
- python - 泡菜和打开文件的区别?
- c# - WPF .Net Core 3.1 WPF 转换不顺利(有趣的问题!!)
- python - 如何在 Python 中绘制此函数?
- jsf - Etat HTTP 500 - 无法找到带有 [0] 参数的方法 [isDelaiAvis]
- scala - Apache Flink Kryo 序列化程序 - ClassNotFoundException
- angular - ngcc 未正确处理声明 FormBuilder 的库(@angular/forms)
- python - 制作一个每次有人玩时都会自行调整的排行榜
- mysql - 我可以在大行数上加快 INSERT IGNORE