I'm building several BLE apps, and have encountered this problem with my BLE protocols as well as external vendors. For the most part, BLE works as intended, but sometimes it will fail to discover services for a specific peripheral and will not work again until I restart or reset my phone.
Has anyone else experienced this problem?
When I'm done with my peripheral, the manager will call the closePeripheralConnection
method. The relevant code:
// Disconnect from peripheral
- (void)closePeripheralConnection
{
NSLog(@"== closePeripheralConnection ==");
// If the peripheral is connected
if (self.peripheral.state == CBPeripheralStateConnected && self.peripheral != nil) {
// Cancel connection
[self.manager cancelPeripheralConnection:self.peripheral];
} else {
[self clearPeripheralSettings];
}
}
// Clear peripheral settings
- (void)clearPeripheralSettings
{
// Clear peripheral variables
self.peripheral = 0;
// Clear services
self.service = 0;
// Clear characteristic values
self.data = 0;
self.notifyCharacteristic = 0;
}
- (void)centralManager:(CBCentralManager *)central didDisconnectPeripheral:(CBPeripheral *)peripheral error:(NSError *)error
{
[self clearPeripheralSettings];
}