Skip to content

Reconnection on disconnection when forceMock == false does not work due #113

Closed
@nonameplum

Description

@nonameplum

Hey,

The problem is that when the delegate call

centralManager(_:didDisconnectPeripheral:error:)

is handled, we would like to use it to automatically "reconnect" by calling

centralManager.connect(peripheral)

since attempts to connect to a peripheral don’t time out.

But it does not work, as after digging into the issue, the underlying CBPeripherals are stored by the CBMCentralManagerNative which is removed on didDisconnectPeripheral so when connect is called it is blocked the if statement as the peripheral is no longer hold in the dictionary.

Potentially a quick fix could be:

func centralManager(_ central: CBCentralManager,
                    didDisconnectPeripheral peripheral: CBPeripheral,
                    error: Error?) {
    manager.delegate?.centralManager(manager,
                                     didDisconnectPeripheral: getPeripheral(peripheral),
                                     error: error)
    // Check if the error is present otherwise the disconnection was explicit
    if error == nil {
        removePeripheral(peripheral)
    }
}

But I guess, the biggest issue is that CBPeripherals are strongly hold by CBMCentralManagerNative in overall.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions