在Swift中使用预定义的UUID发现蓝牙

时间:2020-05-26 05:51:50

标签: swift background core-bluetooth foreground bluetooth-gatt

我正在尝试构建一个可以在Swift中发现蓝牙设备的应用程序(前景应用程序)。 当未提供服务uuid​​时,我可以找到所有可用的设备,例如以下代码:

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

当我指定预定义的UUID时,无法获得设备。 例如,我尝试放入通用访问/设备信息的UUID。 许多网络文章指出,它应该找到所有可用的设备。 但是,我没有从该指令中得到任何设备。

centralManager.scanForPeripherals(withServices: [CBUUID(string: "0x180A"), CBUUID(string: "0x1801"), CBUUID(string: "0x1800"), CBUUID(string: "0x1812")],options: [CBCentralManagerScanOptionAllowDuplicatesKey : true])

该指令是否应添加其他设置?

另外,我可以使用预定义的uuid在后台模式下扫描蓝牙设备吗?

谢谢。

0 个答案:

没有答案