Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is not a but exactly, but a question #598

Closed
barart opened this issue Nov 20, 2023 · 3 comments
Closed

Is not a but exactly, but a question #598

barart opened this issue Nov 20, 2023 · 3 comments
Labels
bug Something isn't working

Comments

@barart
Copy link

barart commented Nov 20, 2023

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 barart added the bug Something isn't working label Nov 20, 2023
@mutasimissa
Copy link
Contributor

mutasimissa commented Nov 20, 2023

@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));
}

@barart
Copy link
Author

barart commented Nov 20, 2023

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

@barart
Copy link
Author

barart commented Nov 21, 2023

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,

@capacitor-community capacitor-community locked and limited conversation to collaborators Nov 21, 2023
@pwespi pwespi converted this issue into discussion #599 Nov 21, 2023

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants