react-native-bluetooth-state icon indicating copy to clipboard operation
react-native-bluetooth-state copied to clipboard

BluetoothState.unsubscribe()

Open albo1337 opened this issue 8 years ago • 3 comments

Hey frostney,

is there a way to unsubscribe BluetoothState? I do BluetoothState.subscribe() in my componentWillMount() and I want to BluetoothState.unsubscribe() in my comonentWillUnmount(),

Best regards, albo

albo1337 avatar Jun 02 '16 06:06 albo1337

That's not available yet through the API (yet), but you can do DeviceEventEmitter.removeListener('centralManagerDidUpdateState');

This may not be what you want though, since that call would get rid of all subscribers.

frostney avatar Jun 02 '16 14:06 frostney

DeviceEventEmitter.removeListener is not a function yet. Not working for me. I think it's because I still use react native v 0.24.1

albo1337 avatar Jun 03 '16 05:06 albo1337

@albo1337 I'm sorry, I mis-remembered the method name. It's DeviceEventEmitter.removeAllListeners('centralManagerDidUpdateState');

frostney avatar Jun 03 '16 07:06 frostney