在连接到广告我感兴趣的特定服务的BLE设备之后,为了发现这项服务,我打电话给:
[self.peripheral discoverServices:@[[self.class serviceUUID]]];
Run Code Online (Sandbox Code Playgroud)
该- (void)peripheral:(CBPeripheral *)peripheral didDiscoverServices:(NSError *)error委托方法被调用,没有错误,但在外围返回服务的数量为0,因此没有特性进一步发现.有谁知道为什么会这样?提前致谢!
以下是委托方法的完整主体.
- (void)peripheral:(CBPeripheral *)peripheral didDiscoverServices:(NSError *)error {
if (error) {
NSLog(@"didDiscoverServices failed: %@", error);
return;
}
NSLog(@"didDiscoverServices succeeded for peripheral: %@.", peripheral.name);
NSLog(@"Number of services: %d", peripheral.services.count);
for (CBService *s in peripheral.services) {
NSLog (@"Discovered service UUID: %@", s.UUID);
if ([s.UUID isEqual:[self.class serviceUUID]]) {
NSLog(@"Discover characteristics...");
[self.peripheral discoverCharacteristics:@[[self.class controlPointCharacteristicUUID], [self.class packetCharacteristicUUID]] forService:s];
}
}
}
Run Code Online (Sandbox Code Playgroud)
控制台显示:
2014-11-27 15:54:51.933 k[197:13362] didDiscoverServices succeeded for peripheral: BootK
2014-11-27 15:54:51.934 k[197:13362] Number of …Run Code Online (Sandbox Code Playgroud)