ios - scanForPeripheralsWithServices :options: and CBCentralManagerScanOptionSolicitedServiceUUIDsKey

标签 ios objective-c core-bluetooth

我在阅读 Apple 的文档时遇到了一个问题。关于 CBCentralManagerScanOptionSolicitedServiceUUIDsKey Apple 的文档指出:

An array (an instance of NSArray) of service UUIDs (represented by CBUUID objects) that you want to scan for.

Specifying this scan option causes the central manager to also scan for peripherals soliciting any of the services contained in the array.

关于 scanForPeripheralsWithServices:options: 的第一个参数,然而:

An array of CBUUID objects that the app is interested in. In this case, each CBUUID object represents the UUID of a service that a peripheral is advertising.

那有什么区别呢?为什么使用其中之一?

最佳答案

通常,蓝牙外围设备会发布服务,而中央设备会扫描这些服务。这是第一个参数涵盖的情况。

然而,在某些情况下,行为是相反的——中央提供服务而外围寻找它。这称为服务请求。当您使用 CBCentralManagerScanOptionSolicitedServiceUUIDsKey 提供一组服务标识符时,您正在提供中央将“通告”给外围设备的服务列表。

启动连接仍然是中心的责任,因此一旦识别出正在请求其中一项服务的外围设备,您将像往常一样收到对 didDiscoverPeripheral 方法的调用.

关于ios - scanForPeripheralsWithServices :options: and CBCentralManagerScanOptionSolicitedServiceUUIDsKey,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31062176/

相关文章:

ios - 如何以编程方式备份​​ Realm 文件?

ios - iOS BLE 应用程序中的重新连接过程

ios - 什么是 IOS 6 等同于 “maximumUpdateValueLength” 得到相同的值?

ios - 从 iPhone 上的弹出 View Controller 传回数据

ios - PKInAppPaymentService 连接上的 ApplePay iOS 错误 - com.apple.passd.in-app-payment - 连接到远程警报 View 服务失败

ios - 来自任何地方的初始 View Controller

ios - 当 deferredlocationupdatesavailable 返回 NO 时,如何使用 ios 高效地获取位置更新

objective-c - 自定义没有 uiappearance 的 uibarbuttonitem

iphone - iPhone 的 SudzC 似乎在每次 Web 服务调用时泄漏 1kB

ios - 重新连接蓝牙后重新连接时应用程序未发现服务