From 45b42f865dd644a13a04a0842c018d1b3c62ca46 Mon Sep 17 00:00:00 2001 From: liwei1dao Date: Sat, 26 Jul 2025 15:01:30 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8A=E4=BC=A0iOS=20ble=E6=96=AD=E5=BC=80?= =?UTF-8?q?=E6=B5=81=E7=A8=8B=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ios/Runner.xcodeproj/project.pbxproj | 4 ++-- .../controllers/devices_controller.dart | 2 -- .../controllers/pairing_controller.dart | 12 ++++++++++- .../Sources/ble_service/BleService.swift | 21 +++++++++++++------ 4 files changed, 28 insertions(+), 11 deletions(-) diff --git a/ios/Runner.xcodeproj/project.pbxproj b/ios/Runner.xcodeproj/project.pbxproj index 8bf262c98..d5a4a6ebc 100644 --- a/ios/Runner.xcodeproj/project.pbxproj +++ b/ios/Runner.xcodeproj/project.pbxproj @@ -527,7 +527,7 @@ CLANG_ENABLE_MODULES = YES; CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements; CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)"; - DEVELOPMENT_TEAM = 537SFY28XS; + DEVELOPMENT_TEAM = K39FB49XKY; ENABLE_BITCODE = NO; INFOPLIST_FILE = Runner/Info.plist; INFOPLIST_KEY_CFBundleDisplayName = "Deep Voice"; @@ -747,7 +747,7 @@ CLANG_ENABLE_MODULES = YES; CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements; CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)"; - DEVELOPMENT_TEAM = 537SFY28XS; + DEVELOPMENT_TEAM = K39FB49XKY; ENABLE_BITCODE = NO; INFOPLIST_FILE = Runner/Info.plist; INFOPLIST_KEY_CFBundleDisplayName = "Deep Voice"; diff --git a/lib/modules/devices/controllers/devices_controller.dart b/lib/modules/devices/controllers/devices_controller.dart index 8dd28c7a8..1beadea7a 100644 --- a/lib/modules/devices/controllers/devices_controller.dart +++ b/lib/modules/devices/controllers/devices_controller.dart @@ -6,8 +6,6 @@ import '/data/services/ble_manager.dart'; import '/data/services/network/api.dart'; import '/routes/app_routes.dart'; import 'package:get/get.dart'; -import 'package:get/get_rx/get_rx.dart'; -import 'package:get/get_state_manager/src/simple/get_controllers.dart'; /* 设备管理 diff --git a/lib/modules/pairing/controllers/pairing_controller.dart b/lib/modules/pairing/controllers/pairing_controller.dart index a8f0e8acc..45912c231 100644 --- a/lib/modules/pairing/controllers/pairing_controller.dart +++ b/lib/modules/pairing/controllers/pairing_controller.dart @@ -2,6 +2,7 @@ import 'dart:convert'; import 'dart:typed_data'; import 'package:app_settings/app_settings.dart'; +import 'package:voitrans/data/models/appconfig_model.dart'; import '/data/models/appconfig.dart'; import '/data/models/user_Info.dart'; import '/data/services/network/api.dart'; @@ -610,6 +611,10 @@ class PairingController extends GetxController { // 检查设备名称是否包含 DeepSound 或 DeapSound final deviceName = device.name; + // 检查是否已有BLE绑定的设备 + final product = AppConfig.config.products + .firstWhere((d) => d.devicename == device.name); + final names = AppConfig.allproductNames(); // 检查是否已有绑定的设备 print("device.address${device.address}"); @@ -746,7 +751,12 @@ class PairingController extends GetxController { } await Future.delayed(Duration(seconds: 1)); } - return 1; + if (product.devicetype == 2) { + //ble设备 必须要扫描到结果 + return 0; + } else { + return 1; + } } return 0; //可以跳转1 diff --git a/local_plugins/ble_service/ios/ble_service/Sources/ble_service/BleService.swift b/local_plugins/ble_service/ios/ble_service/Sources/ble_service/BleService.swift index 66b8d73e2..33f0e9f14 100644 --- a/local_plugins/ble_service/ios/ble_service/Sources/ble_service/BleService.swift +++ b/local_plugins/ble_service/ios/ble_service/Sources/ble_service/BleService.swift @@ -66,6 +66,9 @@ public class BleService: NSObject { // 自动重连队列(统一管理所有待连接的设备) private var pendingReconnectUUIDs = Set() + // 标记是否为主动断开连接 + private var isManualDisconnect = false + private let logger = OSLog(subsystem: "com.yunqiinnovation.ble_service", category: "BleService") // MARK: - Opus音频处理器 @@ -365,6 +368,7 @@ private var cmdReplyType: UInt8 = 0 } if centralManager != nil { + isManualDisconnect = true // 标记为主动断开 updateConnectionState(BleConst.STATE_DISCONNECTING) centralManager?.cancelPeripheralConnection(peripheral) os_log("🔌 开始断开设备连接", log: logger, type: .info) @@ -1420,13 +1424,18 @@ extension BleService: CBCentralManagerDelegate { updateConnectionState(BleConst.STATE_DISCONNECTED) - // 无论是否意外断开,都立即发起新的连接 - if central.state == .poweredOn { - os_log("🔄 立即重新连接设备: %{public}@", log: logger, type: .info, peripheral.identifier.uuidString) - connectPeripheral(peripheral) + // 只有在非主动断开的情况下才重新连接 + if !isManualDisconnect { + if central.state == .poweredOn { + os_log("🔄 意外断开,立即重新连接设备: %{public}@", log: logger, type: .info, peripheral.identifier.uuidString) + connectPeripheral(peripheral) + } else { + os_log("🔄 蓝牙未就绪,添加到重连队列: %{public}@", log: logger, type: .info, peripheral.identifier.uuidString) + pendingReconnectUUIDs.insert(peripheral.identifier) + } } else { - os_log("🔄 蓝牙未就绪,添加到重连队列: %{public}@", log: logger, type: .info, peripheral.identifier.uuidString) - pendingReconnectUUIDs.insert(peripheral.identifier) + os_log("✅ 主动断开连接,不进行自动重连", log: logger, type: .info) + isManualDisconnect = false // 重置标志 } }