Open gpawlik opened 4 years ago
Library seems completely broken in my experience. iOS returns "Native module cannot be null", and Android returns always false, no matter what I do.
Did you find any workaround?
It seems to happen on Samsung phones and tablets but not on a Google Pixel for example... Is this also what you observe?
I started facing this issue after migrating from React Native 0.63.3 to 0.64.0
I found a workeround for this. But its not a best solution for every app and case. But for my app as a temporary solution is acceptable. I am using this library for Android. I need to see bluetooth status of device because i need to reconnect last connected thermal printer automaticly from AsyncStorage if it was once already connected. I have the following issue: in developing mode works this package just fine but in production i am dealing with same problem as above. The bluetooth status is always false even if its on. I found out when i turn off and on manualy bluetooth on device, btStatus is updated correctly. So i decided to turn off and on bluetooth in parent component in useEffect this will reset bluetooth on device and status correctly updated. Problem is, if you have connected some other device to phone it will be disconected. Second thing is it takes some time but you can use spinner if you want until btState is not true. I am using this (React Native 0.63.3) app for Android POS terminal so i am ok with that for now. But I hope this library will be fixed or i find other solution. I am adding my code as example
` import { useBluetoothStatus } from 'react-native-bluetooth-status'; const [btStatus, isPending, setBluetooth] = useBluetoothStatus();
useEffect(() => { loadAuthData(); loadLanguageSetting();
if (!btStatus) {
setBluetooth(false);
setBluetooth(true);
}
if (btStatus) {
if (printers.length === 0) {
BLEPrinter.init()
.then(() => {
searchBluetoothPrinters();
})
};
if (printers.length > 0 && !currentPrinter) {
setStoredPrinter();
};
};
if (!btStatus && printers.length > 0) {
disconnectPrinter();
setPrinters([]);
}
}, [printers, btStatus, isPending]); `
Same issue but issue only found on Android im using below:
Same issue
+1
No matter if the Bluetooth is switched on or off (both general settings and app settings) the state comes as false. Am I missing something?
When I inspect the
state
in the line https://github.com/solinor/react-native-bluetooth-status/blob/master/index.js#L28state
isundefined