Polidea / RxBluetoothKit

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

Added initial state improvement & a minor fix for BluetoothState methods. #371

Closed radumvlad closed 4 years ago

radumvlad commented 4 years ago

This PR will add 1 fix and 1 improvement for BluetoothState methods:

CLAassistant commented 4 years ago

CLA assistant check
All committers have signed the CLA.

radumvlad commented 4 years ago

ping? :(

dariuszseweryn commented 4 years ago

Sorry for such a late reply. I am trying to find someone willing to look into this and opinionate.

As far as I remember the lack of initial state was picked because it is cleaner to add it to the beginning of the stream than to skip the first value (as it is an assumption about the internals of the observable) – merely not having this situation needed in the examples does not mean that noone has it and there was such a situation (I do not remember details now though).

I am not sure about .unknown vs .unsupported either — I need to look through the code and iOS implementation but I expect it was like this for a reason? Did you encountered a situation when .unsupported was returned when the capability was there?

radumvlad commented 4 years ago

Hello @dariuszseweryn ! Regarding the .unknown vs .unsupported: Yes. It happened few times, on several different devices that had bluetooth and we didn't know exactly why or in what case. After we did this change, it stopped happening so we figured out this was the culprit. Regarding the initial state, a pattern that already exists in this sense is Apple's existing implementation. Creating a CBCentralManager with delegate will also call the centralManagerDidUpdateState: method on the delegate informing the user of the initial state. Also, I believe that although the implementation is a little bit simpler, the user might miss-use it and fall in a trap. A common behavior is to check whether the BT state is on/off and act upon that. That means using startWith, and, as I mentioned in my first post, if the users are not careful with it, it might be flaky. Even after acknowledging in a project that we need deferred syntax for that startWith, after a couple of months we accidentally introduced the same bug of forgetting to use it.