1

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

cornr
  • 653
  • 4
  • 20

2 Answers2

4

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.

cornr
  • 653
  • 4
  • 20
  • Thanks man you saved me.. It is worth mentioning that if you put the NSUUID it never sends an error message, which makes it really hard to debug – Alex Mantaut Nov 16 '16 at 04:30
0

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>];
  ...
}
mharper
  • 3,212
  • 1
  • 23
  • 23
  • Thanks, but that does not solve my issue since the `CBPeripheral` is held by a strong reference. – cornr Sep 23 '16 at 15:04