0
如何使用react-native-ble-manager獲取可用藍牙設備的列表。使用react-native-ble-manager獲取可用藍牙設備的列表
如何使用react-native-ble-manager獲取可用藍牙設備的列表。使用react-native-ble-manager獲取可用藍牙設備的列表
首先,你應該:
import BleManager from 'react-native-ble-manager';
,不要忘記:
import { NativeAppEventEmittem } from 'react-native'
然後,你的組件內(我做的componentDidMount
):
2.1。添加句柄NativeAppEventEmitter
上'BleManagerDiscoverPeripheral'
事件:
NativeAppEventEmitter.addListener('BleManagerDiscoverPeripheral',(data) =>
{
console.log(data)
});/*Name of peripheral device*/
2.2。啓動你的BleManager管理器
BleManager.start({showAlert: false});`
2.3。 BleManager.scan([], 30)
,其中第一個值是,如果服務UUID一個數組,第二個是秒長的掃描將如何運行
您可以在官方的lib的頁面react-native-ble-manager
上找到原始的例子