evothings / cordova-ble

Bluetooth Low Energy plugin for Cordova
http://www.evothings.com/
Apache License 2.0
242 stars 103 forks source link

characteristicsCallbacks keys instead of UUID, the hash of object #155

Open bastiaanv opened 6 years ago

bastiaanv commented 6 years ago

I am developing for a company that is using ble to communicate with their climate control system. They want to have all the lighting -for example- to have the same UUID's and that is were this plugin is running into problems within iOS.

The NSMutableDictionary characteristicsCallbacks is using the UUID's as key to save the callbacks. When you (like in my case) are using shared UUID's, some callbacks are being overwritten and will cause problems. When you use the hash of the object, you can bypass this problem. (Note, that you will still need to read before notify, if necessary)

This is how I solved the problem for every self.characteristicsCallbacks: NSNumber* key = [NSNumber numberWithLong:(unsigned long)characteristic.hash]; self.characteristicsCallbacks[key];