ios - 蓝牙扫描未在设置应用程序 (CoreBluetooth) 中发现 iPhone 可见的设备

标签 ios swift bluetooth core-bluetooth

更新:请记住,自 iOS 13 起,CoreBluetooth 现在支持 BLE 和经典蓝牙设备。

来自 Apple :

This year, we've merged the two layers together, and now, you have transparent access to both BR/EDR and low energy without doing anything. Now, what this means for you is without much changes in the API, you can now work with both the classic devices and the low energy devices. [...] This now will allow transparent use of GATT with the BR/EDR devices. It's still running the exact same Bluetooth SIG protocol. There's no changes to that, and so you can look at this specification online on the Bluetooth SIG website. To your application and to the developer, the CBPeripheral APIs are exactly the same. You can still do the same service discovery and be notified of changes to characteristics.

注:BR/EDR是指4.0之前的蓝牙规范的 radio 技术,用于LE设备。更多信息 here .


我正在尝试使用 CoreBluetooth 扫描一些蓝牙设备,但我无法发现它们。

我正在使用 Apple's sample code来自 this talk作为引用。

中央管理器是这样初始化的:

let cbManager = CBCentralManager(delegate: self, queue: nil)

这就是我扫描外围设备的方式:

cbManager.scanForPeripherals(withServices: nil, options: [CBCentralManagerScanOptionAllowDuplicatesKey: true])

因为我不知道我最初应该连接到的 serviceUUID,所以我用 nil 作为 CBUUID 的列表进行扫描。

当发现外围设备时,我会通过 CBCentralManagerDelegatecentralManager(_:didDiscover:advertisementData:rssi:) 方法收到通知,我会保留这些外围设备,这让我可以通过 CBPeripheralDelegateperipheral(_:didDiscoverServices:) 方法发现服务。

发现了一个外设,并发现了它的服务,下次我可以直接连接到那个外设:

cbManager.scanForPeripherals(withServices: [myDiscoveredService], options: nil)

到目前为止,还不错。

但是,我什至无法开始使用未被发现的设备。出现在蓝牙设置应用程序中的许多设备都会出现这种情况。

我如何才能接触到那些设备清晰可见但我无法从代码中发现的设备?

如果我一开始就知道 serviceUUID 会有帮助吗?我如何通过其他方式(可能使用其他工具)获得此类 serviceUUID?

我尝试过但没有用的东西:

  • 使用新Xcode 11 additional tools 中的蓝牙浏览器获取有关设备的信息:虽然我可以获得有关目标蓝牙设备的大量信息(通过“显示设备发现”,然后“获取设备信息...”),但我似乎找不到合适的服务UUID

  • 在扫描时使用数据包记录器实时捕获 iOS 跟踪(来自相同的附加工具包):我看到 HCI 数据包和 HCI 事件,但我似乎无法从该流量中找出任何有值(value)的信息

我正在使用 iOS 13.2 和 Xcode 11.2

最佳答案

CoreBluetooth now supports both BLE and classic Bluetooth devices.

这是对新特性的误解。正如引用的文字所指出的那样,“这现在将允许对 BR/EDR 设备透明地使用 GATT。” (强调)

GATT over BR/EDR 不是蓝牙设备中特别常见的功能,与音频流设备无关。 Core Bluetooth 仍然不支持 A2DP、HID 和 HFP 等其他配置文件。这些可能是您正在使用的设备支持的配置文件。

对于我们这些设计蓝牙产品的人来说,这个新功能确实非常强大和令人兴奋,但我们需要更新我们的固件来支持它。这不是您在硬件方面免费获得的东西。

关于ios - 蓝牙扫描未在设置应用程序 (CoreBluetooth) 中发现 iPhone 可见的设备,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58805091/

相关文章:

visual-c++ - 获取蓝牙配对设备

Android 设备之间的距离(非常准确)

iOS8 触摸位置在风景中受到限制,好像窗口在一侧是肖像?

ios - 在 swift 4 中的类之间移动数据

swift - 如何在 SwiftUI 中保持过渡动画相同的标识

ios - UITableView 与搜索器并在单元格初始加载和搜索 TableView 后选择 UITableViewcell?

ios - 添加为 subview 时未调用 UIViewController viewWillAppear

ios - Splitviewcontroller逻辑不对,内容重复

iphone - 更改图标/产品名称和图像 iPhone

swift - iOS 通过蓝牙获取附近的设备(iPad 和 iPhone)列表