From 76f294c1caf377416dc396a7605758c9b4a8a5bb Mon Sep 17 00:00:00 2001 From: fdp <1286779656@qq.com> Date: Sat, 11 Oct 2025 17:01:03 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=80=80=E5=87=BA?= =?UTF-8?q?=E5=AF=BC=E8=88=AA=E5=A5=94=E6=BA=83=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ios/Classes/AmapViewController.swift | 49 ++++++++++++++----- 1 file changed, 38 insertions(+), 11 deletions(-) diff --git a/local_plugins/amap_service/ios/Classes/AmapViewController.swift b/local_plugins/amap_service/ios/Classes/AmapViewController.swift index c6bda6a36..c421818bf 100644 --- a/local_plugins/amap_service/ios/Classes/AmapViewController.swift +++ b/local_plugins/amap_service/ios/Classes/AmapViewController.swift @@ -56,9 +56,15 @@ class AmapViewController: UIViewController { cleanupResources() } + /** + * 清理资源,包括移除通知观察者 + */ private func cleanupResources() { print("开始清理导航资源") + // 移除通知观察者,防止内存泄漏 + NotificationCenter.default.removeObserver(self, name: NSNotification.Name("ExitNavigation"), object: nil) + // 停止语音合成 speechSynthesizer.stopSpeaking(at: .immediate) @@ -144,21 +150,36 @@ class AmapViewController: UIViewController { print("导航------------------ startNavigation_4") } + /** + * 退出导航并清理资源 + * 添加了nil检查以防止崩溃 + */ @objc private func exitNavigation() { print("导航------------------ 退出导航,清理资源") + + // 安全检查:确保driveManager存在再进行操作 + guard let manager = driveManager else { + print("⚠️ driveManager已为nil,跳过导航清理") + return + } + // 停止导航 - driveManager.stopNavi() - driveManager.removeDataRepresentative(driveView) - driveManager.delegate = nil + manager.stopNavi() - // 移除导航视图 - driveView.delegate = nil - driveView.removeFromSuperview() - driveView = nil + // 安全检查:确保driveView存在再进行操作 + if let view = driveView { + manager.removeDataRepresentative(view) + view.delegate = nil + view.removeFromSuperview() + } else { + print("⚠️ driveView已为nil,跳过视图清理") + } - // 销毁导航管理器 + // 清理管理器 + manager.delegate = nil driveManager = nil - + driveView = nil + // 关闭当前页面 - 修复:使用正确的退出方式 if let navigationController = navigationController { // 如果是在导航控制器中,使用 pop @@ -168,13 +189,19 @@ class AmapViewController: UIViewController { dismiss(animated: true, completion: nil) } } + + /** + * 添加通知监听器 + * 使用弱引用避免循环引用和对象销毁后的调用 + */ private func addNSNotification(){ NotificationCenter.default.addObserver( forName: NSNotification.Name("ExitNavigation"), object: nil, queue: .main - ) { _ in - self.exitNavigation() + ) { [weak self] _ in + // 使用弱引用避免在对象销毁后调用方法 + self?.exitNavigation() } } } From 939e4a2fce602c93e2fdff0a9a33889e9a4a100a Mon Sep 17 00:00:00 2001 From: fdp <1286779656@qq.com> Date: Sat, 11 Oct 2025 19:25:22 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=94=B5=E9=87=8F?= =?UTF-8?q?=E5=92=8C=E8=BF=9E=E6=8E=A5=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/modules/home/views/home_view.dart | 3 --- lib/modules/pairing/controllers/pairing_controller.dart | 4 ++-- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/lib/modules/home/views/home_view.dart b/lib/modules/home/views/home_view.dart index 5e5a72be4..745d19381 100644 --- a/lib/modules/home/views/home_view.dart +++ b/lib/modules/home/views/home_view.dart @@ -92,7 +92,6 @@ class HomeView extends GetView { // 设备状态卡片 IntroStepBuilder( - key: const ValueKey('home_device_status'), // 添加唯一key group: 'home', order: 1, onWidgetLoad: () { @@ -121,7 +120,6 @@ class HomeView extends GetView { SizedBox(height: 20.h), IntroStepBuilder( - key: const ValueKey('home_wakeup_guide'), // 添加唯一key group: 'home', order: 2, getOverlayPosition: IntroOverlayBuilder.overlayPosition, @@ -797,7 +795,6 @@ class HomeView extends GetView { Expanded( flex: 1, child: IntroStepBuilder( - key: const ValueKey('home_ai_assistant'), // 添加唯一key group: 'home', order: 3, getOverlayPosition: IntroOverlayBuilder.overlayPosition, diff --git a/lib/modules/pairing/controllers/pairing_controller.dart b/lib/modules/pairing/controllers/pairing_controller.dart index 3fb4e4ceb..8b1d2e43b 100644 --- a/lib/modules/pairing/controllers/pairing_controller.dart +++ b/lib/modules/pairing/controllers/pairing_controller.dart @@ -803,13 +803,13 @@ class PairingController extends GetxController with WidgetsBindingObserver { } } else { //未绑定设备 - + _bleManager.clearPairedDevices(); Logger.i(_tag, '验证时BLE状态: $currentBleState'); if (currentBleState == 2) { //已连接 清理 // BleConnectionState.connected Logger.i(_tag, 'BLE已连接,断开并清理缓存'); - _bleManager.clearPairedDevices(); + _bleManager.disconnect(); } }