简体   繁体   中英

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

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.

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, eg:

@property (nonatomic, string) CBPeripheral *peripheral;

...

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM