Following connection to a BLE device which is advertising a specific service I'm interested in, in order to discover this service, I'm calling:
[self.peripheral discoverServices:@[[self.class serviceUUID]]];
The - (void)peripheral:(CBPeripheral *)peripheral didDiscoverServices:(NSError *)error
delegate method gets called with no error, yet the number of services returned for the peripheral is 0, and therefore no characteristics are further discovered. Does anyone have any idea why this is happening? Thanks in advance!
Below is the full body of the delegate method.
- (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];
}
}
}
The console shows:
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 services: 0
The only thing I can think of is
[self.class serviceUUID]
does not match the UUID of the service you're looking for. When you initiate the scan, are you filtering by service UUID?If not, that might explain why you're able to discover and connect to it, but not discover that specific service.