Browse Source

修复ios

newdev_shunjiawei
fdp 1 year ago
parent
commit
109ea6e409
  1. 10
      local_plugins/ble_service/ios/ble_service/Sources/ble_service/BleService.swift
  2. 3
      local_plugins/ble_service/ios/ble_service/Sources/ble_service/SwiftBleServicePlugin.swift

10
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)

3
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":

Loading…
Cancel
Save