IOS Core Bluetooth: advertised service not found on peripherals

After connecting to a BLE device that advertises a specific service that interests me, to open this service, I call:

[self.peripheral discoverServices:@[[self.class serviceUUID]]]; 

The delegate method - (void)peripheral:(CBPeripheral *)peripheral didDiscoverServices:(NSError *)error is called without errors, but the number of services returned for the periphery is 0, and therefore no signs were found. Does anyone know why this is happening? Thanks in advance!

Below is the full text 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 
+5
source share
1 answer

The only thing I can think of is that [self.class serviceUUID] does not match the UUID of the service you are looking for. When you run a scan, do you filter using the service's UUID?

 [self.centralManager scanForPeripheralsWithServices:[self.class serviceUUID] options:nil]; 

If not, this may explain why you can detect and connect to it, but not discover this particular service.

0
source

Source: https://habr.com/ru/post/1207813/


All Articles