3
import {BleManager} from 'react-native-ble-plx';

const DeviceManager = new BleManager();

export const scan = function scan() {
    const subscription = DeviceManager.onStateChange((state) => {
        if (state === 'PoweredOn') {
          DeviceManager.startDeviceScan(null, null, (error, device) => {
            if (error) {
              console.log("error",error);
            }
            if (device !== null) {
                console.log("device found ----> [id,name]", device.id, device.name);
            }
          });
          subscription.remove();
        }
    }, true);
}

这是我扫描附近设备的代码。当我运行该应用程序时,尽管附近有其他设备(支持蓝牙 LE 的手机)已打开蓝牙,但仅检测到我的笔记本电脑。

同样对于我的笔记本电脑,仅显示设备 ID,设备名称显示为空。

我的代码是否缺少检测所有附近设备和检测到设备的所有数据的内容?

4

0 回答 0