使用react-native-ble-plx库,每当我扫描设备时,我都会获得MAC地址,该MAC地址在每次打开和关闭附近的设备时都会更改,因此,如果设备存在或不存在,我应该如何比较?诸如device.name,device.localName的字段为null。以下是我扫描附近设备的代码。
const App = () =>{
const DeviceManager = new BleManager();
const subscription = DeviceManager.onStateChange((state) =>{
if(state === 'PoweredOn'){
console.log('I am powered On');
scan();
subscription.remove();
}
},true)
const scan = () =>{
DeviceManager.startDeviceScan([],null,(error,device)=>{
console.log('Scanning');
if(device === null){
console.log(error);
}
if(device !== null){
console.log('found devices');
console.log(device.id);
console.log(device.name);
}
})
}