You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently BleManager.start has to be called once before using any other BleManager methods. In our app, we want to defer this to the point where a BLE-related feature is actually needed and after checking permissions. To avoid calling it multiple times, we keep track of the started state and a module-level variable, like this:
// Define a module-scoped variable to track BleManager initialization// unfortunately there's no way to ask BleManager if it has been startedexportletisBleManagerInitialized=false;exportconstsetBleManagerInitialized=(value: boolean)=>{isBleManagerInitialized=value;};constcheckBTState=async()=>{if(!isBleManagerInitialized){awaitBleManager.start({showAlert: false});setBleManagerInitialized(true);}returnBleManager.checkState();};// permission checking code later calls checkBTState()
...
// other modules can import isBleManagerInitialized and setBleManagerInitialized(true)
While this works, we have to be careful not to add BleManager.start anywhere else. It would be great if we could instead ask BleManager to check if it has already been started. Would that be something to consider to add to the API?
The text was updated successfully, but these errors were encountered:
Currently
BleManager.start
has to be called once before using any otherBleManager
methods. In our app, we want to defer this to the point where a BLE-related feature is actually needed and after checking permissions. To avoid calling it multiple times, we keep track of the started state and a module-level variable, like this:While this works, we have to be careful not to add
BleManager.start
anywhere else. It would be great if we could instead ask BleManager to check if it has already been started. Would that be something to consider to add to the API?The text was updated successfully, but these errors were encountered: