【发布时间】:2019-06-15 13:48:20
【问题描述】:
我想做的是:
- 将值写入特征
- 如果在一定时间内连接失败,则作为超时错误处理
- 如果连接成功,延长或忽略超时并保持连接
我实现了 1 和 2,但我如何实现 3? 非常感谢您的帮助。
我的来源:
manager = CentralManager(queue: .main, options: options)
manager!.observeState()
.startWith(self.manager!.state)
.filter { $0 == .poweredOn }
.timeout(3.0, scheduler: MainScheduler.instance)
.take(1)
.flatMap { _ in self.manager!.retrievePeripherals(withIdentifiers: [peripheralUUID])[0].establishConnection() }
.timeout(5.0, scheduler: MainScheduler.instance) // (A) Set connection timeout here
.flatMap{ $0.writeValue(data, for: BLECharacteristic.char, type: .withResponse)}
.subscribe(onNext: { char in
// (B) I want to extend timeout here
// Handle success
}, onError: { (error) in
// Handle error
}, onCompleted: nil, onDisposed: nil)
【问题讨论】:
-
你有没有想过使用去抖算子reactivex.io/documentation/operators/debounce.html?
-
考虑到你有
take(1)。更改timeout的参数是没有意义的。也许您想要做的与您描述的有所不同?
标签: ios swift bluetooth rx-swift