innoveit / react-native-ble-manager

React Native BLE communication module
http://innoveit.github.io/react-native-ble-manager/
Apache License 2.0
2.13k stars 768 forks source link

Fixing uuidAsString calls in Helper key method #1237

Closed BMR11 closed 5 months ago

BMR11 commented 5 months ago

In iOS code, We are building a unique key for a given peripheral / characteristic / descriptor, with using Helper.key method.

Here we are using peripheral.uuidAsString to build the final key but as this is a function and not a value, this will always return instead of the actual uuid string. and so, if we are reading BLE characteristic values for different peripherals, it will always return the same key. And eventually app will be updated with the same readcallbacks every time instead of reporting readcallbacks as per peripheral. To get the correct string we should be calling peripheral.uuidAsString() and so we get a unique key built for each use-case

Understanding by printing values:

static func key(forPeripheral peripheral: CBPeripheral,
                    andCharacteristic characteristic: CBCharacteristic) -> String {
        print("uuidAsString=>%@",peripheral.uuidAsString)
        print("uuidAsString()=>%@",peripheral.uuidAsString())
        print("old1 %@","\(String(describing: peripheral.uuidAsString))|\(characteristic.uuid)")
        print("new1  %@","\(String(describing: peripheral.uuidAsString()))|\(characteristic.uuid)")
        return "\(String(describing: peripheral.uuidAsString))|\(characteristic.uuid)"
    }

We get logs

uuidAsString=>%@ (Function)
uuidAsString()=>%@ my-actual-uuid-for-this-peripheral
old1 %@ (Function)|my-actual-uuid-for-this-characteristic
new1  %@ my-actual-uuid-for-this-peripheral|my-actual-uuid-for-this-characteristic
BMR11 commented 5 months ago

@marcosinigaglia , This is a syntax usage error that is replacing calls from peripheral.uuidAsString to peripheral.uuidAsString(). In our use case, we are reading multiple ble sensors and the app is always getting the same read values due to this issue, Let me know if you need to have more details on this.

marcosinigaglia commented 5 months ago

Hi @BMR11 thanks!