From 109ea6e409aabc4bcfe58511a82db595a7e44f11 Mon Sep 17 00:00:00 2001 From: fdp <1286779656@qq.com> Date: Wed, 10 Sep 2025 18:39:32 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dios?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ble_service/Sources/ble_service/BleService.swift | 10 ++++++---- .../Sources/ble_service/SwiftBleServicePlugin.swift | 3 ++- 2 files changed, 8 insertions(+), 5 deletions(-) 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 3ce8a26aa..87c242ef8 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 @@ -290,7 +290,7 @@ private var cmdReplyType: UInt8 = 0 // 完整UUID cbuuid = CBUUID(string: uuidStr) } else { - os_log("⚠️ 无效的UUID格式: %{public}@", log: logger, type: .warning, uuidStr) + os_log("⚠️ 无效的UUID格式: %{public}@", log: logger, type: .default, uuidStr) continue } serviceUUIDs.append(cbuuid) @@ -300,11 +300,13 @@ private var cmdReplyType: UInt8 = 0 } } - // 开始扫描,使用构建的服务UUID数组进行过滤 - manager.scanForPeripherals(withServices: serviceUUIDs.isEmpty ? nil : serviceUUIDs, options: [ + // // 开始扫描,使用构建的服务UUID数组进行过滤 + // manager.scanForPeripherals(withServices: serviceUUIDs.isEmpty ? nil : serviceUUIDs, options: [ + // CBCentralManagerScanOptionAllowDuplicatesKey: true // 允许重复以获取更新的广播数据 + // ]) + manager.scanForPeripherals(withServices: nil , options: [ CBCentralManagerScanOptionAllowDuplicatesKey: true // 允许重复以获取更新的广播数据 ]) - let filterInfo = serviceUUIDs.isEmpty ? "无过滤" : "过滤器数量: \(serviceUUIDs.count)" os_log("🔍 开始扫描BLE设备(%{public}@),超时时间: %.1f秒", log: logger, type: .info, filterInfo, timeout) diff --git a/local_plugins/ble_service/ios/ble_service/Sources/ble_service/SwiftBleServicePlugin.swift b/local_plugins/ble_service/ios/ble_service/Sources/ble_service/SwiftBleServicePlugin.swift index dd9d07f14..eb7fc5215 100644 --- a/local_plugins/ble_service/ios/ble_service/Sources/ble_service/SwiftBleServicePlugin.swift +++ b/local_plugins/ble_service/ios/ble_service/Sources/ble_service/SwiftBleServicePlugin.swift @@ -112,9 +112,10 @@ public class SwiftBleServicePlugin: NSObject, FlutterPlugin { case "startScan": let arguments = call.arguments as? [String: Any] let timeout = (arguments?["timeout"] as? Double) ?? 15.0 + let uuids = (arguments?["uuids"] as? [String]) ?? [] os_log("🔍 开始传统BLE扫描,超时: %.1f秒", log: logger, type: .info, timeout) - BleService.shared.startScan(timeout: timeout) + BleService.shared.startScan(timeout: timeout, uuids: uuids) result(true) case "stopScan":