react-native-ble-manager 没有显示移动蓝牙和蓝牙耳机

react-native-ble-manager is not showing Mobile Bluetooth and BLUETOOTH EARPHONES

我正在尝试在我的应用程序中实现蓝牙服务。但是当扫描正在盯着我的应用程序到那个时候没有显示移动蓝牙和蓝牙耳机蓝牙时。

仅在控制台中显示没有名称的蓝牙。

请帮忙解决这个问题。

import React, { Component } from 'react';
import { NativeModules, NativeEventEmitter, View, Text } from 'react-native';
import BleManager from 'react-native-ble-manager';

const BleManagerModule = NativeModules.BleManager;
const bleManagerEmitter = new NativeEventEmitter(BleManagerModule);


export default class App extends Component{
  state = {
    peripherals: new Map(),
  };

  componentDidMount() {
    BleManager.start({ showAlert: false })
  
    this.handlerDiscover = bleManagerEmitter.addListener(
      'BleManagerDiscoverPeripheral',
      this.handleDiscoverPeripheral
    );
  
    this.handlerStop = bleManagerEmitter.addListener(
      'BleManagerStopScan',
      this.handleStopScan
    );
  
    this.scanForDevices(); // I chose to start scanning for devices here
  }
  
  scanForDevices() {
    BleManager.scan([], 30);
  }
  
  handleDiscoverPeripheral = (peripheral) => {
    console.log('Got ble peripheral', peripheral);
    const { peripherals } = this.state;
  
    if (peripheral.name) {
      peripherals.set(peripheral.id, peripheral.name);
    }
    this.setState({ peripherals });
  };

  handleStopScan = () => {
    console.log('Scan is stopped. Devices: ', this.state.peripherals);
  }

  render(){
    return(
      <View>
        <Text>Bluetooth</Text>
      </View>
    )
  }
}

react-native-ble-manager 支持您的 phone 和蓝牙低功耗 (BLE) 设备之间的通信。 BLE 设备需要通告它们的存在才能被检测到。请记住,BLE 与经典蓝牙不同。

您只能使用 react-native-ble-manager 检测 BLE 设备。如果您找不到您的设备,它们可能不是 BLE 设备,而是经典蓝牙设备。其他手机 phone 通常不宣传 BLE 服务,需要一个应用程序来宣传。 Bluetooth Headphones 可能使用 BLE 实现某些功能,但音频传输是使用 Bluetooth Classic 处理的。

您可以使用 nRF Connect 等通用 BLE 扫描仪应用程序来扫描附近的 BLE 设备。该应用程序甚至允许您在另一个 phone 上启动 GATT 服务器,以便使用 BLE 访问它。