Polidea / RxBluetoothKit

iOS & OSX Bluetooth library for RxSwift
Apache License 2.0
1.41k stars 366 forks source link

DidConnect to peripheral but Observe Connection not receive call back #366

Closed morris-lu closed 4 years ago

morris-lu commented 4 years ago

Describe the bug

Hi, thanks for the awesome framework. Currently, I using establish connection and subscribe observe connection. Here is my code

BluetoothManager.shared.peripheralManager = self.manager.observeState()
            .startWith(manager.state)
            .filter { $0 == .poweredOn }
            .flatMap { _ in self.manager.scanForPeripherals(withServices: [servicesId]) }
            .flatMap { _ in peripheral.establishConnection() }
            .subscribe(onNext: { peripheral in
                self.devicesTableView.reloadData(with: .fade)
                print("Connected to: \(peripheral)")
            },
                       onError: { error in
                        print("connect error", error)

            }
        )

I got log

didConnect(to: Peripheral(uuid: 62C8B54B-81F7-0E88-284A-A84460190461, name: Optional("E1AA0000          "))) 

but I didn't get call back in observe connection subscribe, when I click establish again I'll receive call back in observe connection. Do I miss any setup? Thank you very much.

Environment:

morris-lu commented 4 years ago

Hi, I think it was my fault, I declare let manager = CentralManager(queue: .main) in two classes.

Now I only declare one is success to subscribe connection call back, thanks.