cornr
cornr

Reputation: 693

CoreBluetooth on iOS10: Timeout after CBPeripheral discoverServices

Our App connects to Bluetooth LE Devices via CoreBluetooth.

On iOS 8 and 9 everything works correctly. On iOS 10 we geht a Timeout Error (Error Domain=CBErrorDomain Code=6 "The connection has timed out unexpectedly.")
in the CBCentralManagerDelegate:

- (void)centralManager:(CBCentralManager *)central didDisconnectPeripheral:(CBPeripheral *)peripheral error:(nullable NSError *)error;

after calling discoverServices on a connected CBPeripheral.

Does anyone know whats going wrong? Is this an iOS 10 issue? Is there a certain BLE Log to check?

Setup iOS 10.0.1 (14A403) on iPad Pro 9.7 with a Nordic Semiconductor nRF51822

Upvotes: 1

Views: 2523

Answers (2)

cornr
cornr

Reputation: 693

OK, I solved the Problem. I mixed up CBUUID and NSUUID
starting with iOS 10 CBPeripheral discoverServices only accepts CBUUID. NSUUID does not work anymore. Maybe NSUUID only worked accidentally on older iOS versions. The documentation clearly states:

A list of CBUUID objects representing the service types to be discovered.

NSArray *services = @[
    [CBUUID UUIDWithString:ServiceUUID] //Correct
    //[[NSUUID alloc] initWithUUIDString:ServiceUUID] //Does work on iOS 9 but not on iOS 10
];
[self.peripheral discoverServices:services];

looking forward to port the app to strongly typed Swift.

Upvotes: 4

mharper
mharper

Reputation: 3272

Make sure you aren't allowing the CBPeripheral to be deallocated before peripheral:didDiscoverServices: is called in your CBCentralManagerDelegate. This is easily accomplished by assigning the peripheral to a property, e. g.:

@property (nonatomic, string) CBPeripheral *peripheral;

...

- (void)centralManager:(CBCentralManager *)central didConnectPeripheral:(CBPeripheral *)peripheral {

  self.peripheral = peripheral
  [peripheral discoverServices:<desired service UUIDs>];
  ...
}

Upvotes: 0

Related Questions