Skip to content
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

[iOS] [checkState] Always returns 'unknown' #1196

Open
joenini opened this issue Apr 8, 2024 · 5 comments
Open

[iOS] [checkState] Always returns 'unknown' #1196

joenini opened this issue Apr 8, 2024 · 5 comments

Comments

@joenini
Copy link

joenini commented Apr 8, 2024

Describe the bug
On iOS, using bleManager.checkState() always returns 'unknown'. I tried with Bluetooth permissions granted/ not granted, and with Bluetooth on/ off.

Smartphone (please complete the following information):

  • Device: [e.g. iPhone8/11]
  • OS: [e.g. iOS16/17]
  • react-native-ble-manager version: 11.3.2
  • react-native version: 0.72.6

Additional context
However, the listener for BleManagerDidUpdateState is receiving the correct state ['unauthorized', 'off', 'on'].
Also, on Android bleManager.checkState() returns the correct state.

@lucaswitch
Copy link
Contributor

Make sure to wrap it on a "await" call. I'm also using 11.3.2 and never had this problem.
Screenshot 2024-04-08 at 14 05 41

@joenini
Copy link
Author

joenini commented Apr 8, 2024

I do have await, same as in your screenshot.

@hisstoryxx
Copy link

I have same ISSUE!!
using 11.4.0 version in iOS

@hisstoryxx
Copy link

hisstoryxx commented Apr 26, 2024

I think this function doesn't guarantee completion.
await BleManager.checkState();

so need to check the state of BleManagerDidUpdateState

await BleManager.start();

    const listener = BleManager.addListener(
      BleEventType.BleManagerDidUpdateState,
      event => {
        console.log(
          `${new Date().toISOString()} =============================================`,
        );
        console.log(event);

        BleManager.removeAllListeners(
          BleEventType.BleManagerDidUpdateState,
        );
      },
    );

@lucaswitch
Copy link
Contributor

Make sure to call functions just after start method cause ble manager needs to have CBCentralManager instance ready to do proper work, see: https://github.com/innoveit/react-native-ble-manager/blob/master/ios/BleManager.swift
Probably not a library issue.

There's the behaviors:

checkState(imperative): Gives the current state even if it's not ready will report unknown asap.

BleManagerDidUpdateState(Event driven): As soon CBCentralManager is ready with start to report changes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants