We have an app that is communicating with our own BLE device. When we push a new firmware we reboot and we get the centralManager: didDisconnectPeripheral: error: and the centralManager: didConnectPeripheral: but when we call [peripheral discoverServices:nil] we never get the callback for peripheral: didDiscoverServices:. We get it when we initially connect but not when we reconnect. CoreBluetooth seems to know what the services and characteristics are because we can interact with the device but we want to be able to write a characteristic right after the reboot but can't find a reliable way to tell when that is.
-= EDIT =-
This is the code we're using for writing characteristics. When we try calling it on the second call to didConnect it fails because the peripheral doesn't have any services:
+(void)writeData:(NSData*)data toPeripheral:(CBPeripheral*)peripheral service:(NSString*)sCBUUID characteristic:(NSString*)cCBUUID
{
// Sends data to BLE peripheral to process HID and send EHIF command to PC
for(CBService *service in peripheral.services)
{
if([service.UUID.stringValue isEqualToString:sCBUUID])
{
for(CBCharacteristic *characteristic in service.characteristics)
{
if([characteristic.UUID.stringValue isEqualToString:cCBUUID])
{
/* EVERYTHING IS FOUND, WRITE characteristic ! */
[peripheral writeValue:data forCharacteristic:characteristic type:CBCharacteristicWriteWithResponse];
return;
}
}
}
}
}
didConnectPeripheral? - Paulw11NSArray * peripherals = [self.centralManager retrieveConnectedPeripheralsWithServices:self.allServices];which returns a list of devices that CoreBluetooth thinks it's connected to. Since it has those caches calling discoverServices never actually does anything. - CaseyB