Rx蓝牙套件调用以检索外围设备第二次失败



我正在使用RxBluetoothKit 3.0.6,并在视图控制器中具有以下代码:

override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view.
    DDLogDebug("DEviceChooser viewDidLoad")
    self.navigationItem.rightBarButtonItem = self.editButtonItem
    //let timerQueue = DispatchQueue(label: "com.polidea.rxbluetoothkit.timer")
    //scheduler = ConcurrentDispatchQueueScheduler(queue: timerQueue)
    scheduler = MainScheduler.instance
    if let favs = EmaxProfile.getFavourites() {
        DDLogDebug("Got (favs.count) favourites")
        var uuids: [UUID] = []
        for (s) in favs {
            if let uuid = UUID(uuidString: s) {
                uuids.append(uuid)
            }
        }
        DDLogDebug("Got (uuids.count) uuids")
        if (!uuids.isEmpty) {
            let cbcm = CBCentralManager()
            let devs = cbcm.retrievePeripherals(withIdentifiers: uuids)
            DDLogDebug("Direct call to CBCentralManager.retrievePeripherals returned (devs.count) entries")
            self.manager.retrievePeripherals(withIdentifiers: uuids)
                    .subscribeOn(MainScheduler.instance)
                    .subscribe(onNext: {
                        DDLogDebug("Got ($0.count) devices from RXBluetoothKit")
                        //var list = self.devices[self.favourites]
                        for (dev) in $0 {
                            DDLogDebug("Adding device (dev.name)")
                            let btDev = BTDevice(dev)
                            btDev.suitable = true
                            self.devices[self.favourites].append(btDev)
                        }
                        if (self.devices[self.favourites].isEmpty) {
                            self.startScanning()
                        } else {
                            self.tableView.reloadData()
                        }
                    }, onCompleted: {
                        DDLogDebug("Retrieve complete")
                    }).addDisposableTo(disposeBag)
        } else {
            startScanning()
        }
    } else {
        startScanning()
    }
}

因此,在viewDidLoad()中,我正在检索以前扫描的设备列表,由其UUID存储,并尝试在不扫描的情况下检索它们。如果我调用核心蓝牙retrievePeripherals它每次都能正常工作。但是,使用 Rx 蓝牙管理器调用第二次失败 - 即当我运行程序时,第一次显示此视图时它工作正常。如果我点击"返回",则立即重新打开视图,则onNext:关闭和onComplete:关闭都不会执行。日志输出为:

2017-01-12 19:55:13.824088 BlueMAX[559:216265] DEviceChooser viewDidLoad
2017-01-12 19:55:13.835820 BlueMAX[559:216297] Got 1 favourites
2017-01-12 19:55:13.836196 BlueMAX[559:216265] Got 1 uuids
2017-01-12 19:55:13.838832 BlueMAX[559:216265] Direct call to CBCentralManager.retrievePeripherals returned 1 entries
2017-01-12 19:55:13.846427 BlueMAX[559:216265] Got 1 devices from RXBluetoothKit
2017-01-12 19:55:13.846927 BlueMAX[559:216312] Adding device Optional("DEV")
2017-01-12 19:55:13.849145 BlueMAX[559:216265] Retrieve complete
2017-01-12 19:55:13.909986 BlueMAX[559:216312] [CoreBluetooth] XPC connection invalid
2017-01-12 19:55:21.515795 BlueMAX[559:216269] Saved 1 favourites, now exiting DeviceChooser
2017-01-12 19:55:22.054481 BlueMAX[559:216335] [CoreBluetooth] XPC connection invalid
2017-01-12 19:55:24.650717 BlueMAX[559:216269] DEviceChooser viewDidLoad
2017-01-12 19:55:24.651417 BlueMAX[559:216269] Got 1 favourites
2017-01-12 19:55:24.651646 BlueMAX[559:216312] Got 1 uuids
2017-01-12 19:55:24.654465 BlueMAX[559:216335] Direct call to CBCentralManager.retrievePeripherals returned 1 entries
2017-01-12 19:55:24.679889 BlueMAX[559:216269] [CoreBluetooth] XPC connection invalid

我不确定"XPC连接无效"消息是否与此有关。

这是一个错误,还是我做错了什么?

你能告诉我self.manager是从外部注入的,还是在VC的初始化中重新创建的吗?它究竟是如何创建的?

RxBluetoothKit做的只是调用与上面示例中相同的方法并将其映射到Observable序列。你能跳到源代码和调试器,看看这行是否: return self.centralManager.retrievePeripherals(withIdentifiers: identifiers) 每次都叫?

也许是为了方便起见 - 请将此报告为 Github 的问题,因为可能需要一段时间才能重现该问题。谢谢

最新更新