外围设备的 UUID 是普通字符串



嘿,我有一个问题,我的一个朋友构建了一个应该与iPhone连接的设备。但是现在我正在构建应用程序,并且遇到了一个问题,我想将外围设备的uuid与我选择的uuid进行比较。如果我调用函数didDiscoverServices,我会得到如下内容:使用 UUID 找到的服务:设备信息使用 UUID 找到的服务:电池

但我无法将其与以下人员进行比较:如果([服务。UUID isEqual:[CBUUID UUIDWithString:@"Battery"]]) {....}因为字符串不是 UUID。我现在能做什么?还有其他比较服务的可能性吗?(服务描述也是一个随机数)

根据

文档0x180F电池的UUID:https://developer.bluetooth.org/gatt/services/Pages/ServicesHome.aspx
所以你必须写:[service.UUID isEqual:[CBUUID UUIDWithString:@"0x180F"]]或你的朋友放的UUID。
您必须了解低功耗蓝牙中的 UUID 是 16 位或 128 位(用于自定义)。阅读文档 https://developer.apple.com/library/ios/documentation/NetworkingInternetWeb/Conceptual/CoreBluetooth_concepts/PerformingCommonPeripheralRoleTasks/PerformingCommonPeripheralRoleTasks.html 或至少UUIDWithString之一应该可以帮助您理解。

最新更新