Search code examples
ioscore-bluetooth

CBCentralManager -- willRestore -- CBCentralManagerRestoredStateScanServicesKey


When restoring state with CBCentralManager the dictionary sometimes contains a scanned peripheral's UUID

internal func centralManager(_ central: CBCentralManager, willRestoreState dict: [String : Any]) {
    let scannedPeripherals = dict[CBCentralManagerRestoredStateScanServicesKey] as? [CBUUID]
}

In contrast to willRestoreState, didDiscoverPeripheral provides CBPeripheral objects that the Central Manager can connect with.

My question is, what can I do with the UUID? The Central Manager can't connect or detect the device when this happens.


Solution

  • Since the peripheral has already been discovered you don't need to scan for it.

    You can pass the identifier to retrievePeripherals(withIdentifiers): in order to obtain a CBPeripheral instance that you can connect to.