Polidea / RxBluetoothKit

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

Conceptual questions. Why do we have to discover services again? #355

Open Ricardo1980 opened 4 years ago

Ricardo1980 commented 4 years ago

Hello,

There is something I don't understand here:

manager.scanForPeripherals(withServices: [serviceId])
    .take(1)
    .flatMap { $0.peripheral.establishConnection() }
    .flatMap { $0.discoverServices([serviceId]) }
    .flatMap { Observable.from($0) }
    .flatMap { $0.discoverCharacteristics([characteristicId]) }
    .flatMap { Observable.from($0) }
    .flatMap { $0.readValue() }
    .subscribe(onNext: { print("Value: \($0.value)") })

What is the reason of using discoverServices if we already know that the device has the service we want? (using scanForPeripherals)

And another question, in iOS, can I use a service that is not being advertised? It seems in android is possible but according to this, that is not possible in iOS (second response): https://stackoverflow.com/questions/45896372/ios-how-to-discover-unadvertised-services-on-a-ble-peripheral

What do you think about that? Thanks a lot.

biangou commented 4 years ago

using scanForPeripherals only get peripheral and advertisementData,sure,you can get serverid from advertisementData,but the serverid from advertisementData is not always equal to the serviceid from discoverServices