capacitor-community/bluetooth-le

Is not a but exactly, but a question

Closed this issue · 3 comments

Is there a way to check if its already initialized? the isEnabled() is for check if bt is enabled on system, no if the component was already initialized, the initialize() function dont return anything to see if it was initialized or not

@barart Please remove the bug tag amd move this to discussion board.
wrap the initialize() with try/catch block and you can also use isEnabled() , I don't think there is another way in the native platforms itself to check for initialization

try {
   await BleClient.initialize();
   let isBtEnabled = await BleClient.isEnabled();
   if (!isBtEnabled) {
      throw new Error("BLE not available");
   }
} catch (e) {
   console.log(String(e));
}

@mutasimissa THanks, will check, i cant change the label (i dont have permission)

i would like to ask a enhancement on this, actually all the functions thow a error "Bluetooth LE not initialized." if it is not initialized, the isEnabled() suppose to return true or false if is enabled o not, but, if it is not initialized it dont return "false" it throws the error mentioned, so, all functions "knows" that ble is not initialized but as error; based on this, i think the isEnabled() function should returns false if BLE is not initialized instead throwing a error, maybe more complete, it could return true, false, notinitialized and this would be helpful to know if ble was initialized or not, atm my workaround was to create promise listener and check if it was true, if not then read the error message and compare the string "Bluetooth LE not initialized." with the error, at this point my app will now if its initialized or not,