首页 > 解决方案 > PolideaHow 可以将 Notify value 设置为 True on a specific Characteristic 和 Polidea/RXBluethootKit with IOS

问题描述

嗨,我正在尝试通过 BLE 将一些数据写入设备,我正在使用 RXBluethootKit for Swift 但在写入值之前我很难在特定特征中设置“通知”“开启”。

这是我的代码:

func connect(for state: BluetoothState)  -> Observable<Characteristic>   {
        return manager.observeState()
            .startWith(state)
            .filter { $0 == .poweredOn }
            .flatMap { _ in self.manager.scanForPeripherals(withServices: [self.PERDIX_UUID]) }
            .take(1)
            .flatMap { $0.peripheral.establishConnection()
            .flatMap { $0.discoverServices([self.PERDIX_UUID]) }.asObservable()
            .flatMap { Observable.from($0) }
            .flatMap { $0.discoverCharacteristics([self.PERDIX_CHAR_UUID])}.asObservable()
            .flatMap { Observable.from($0) }
    }


connect(for: state)
            .subscribe(onNext: { characteristic in
                print("Discovered characteristic: \(characteristic.characteristic.uuid)")
                self.result.text = characteristic.characteristic.uuid.uuidString
                characteristic.writeValue(data as Data, type: .withResponse)
                    .subscribe { event in
                        //respond to errors / successful read
                }

        })

有什么建议吗?谢谢

标签: swiftbluetooth-lowenergy

解决方案


推荐阅读