我正在使用react-native-ble-plx在我的应用程序中实现蓝牙
蓝牙扫描运行良好,但是它在安卓中包含副本,而在iOS中运行良好,因为allowDuplicates在iOS中默认为false。
在android中,缺省值为true。请提供使用react-native-ble-plx的allowDuplicates属性过滤重复项的解决方案
文档中startDeviceScan的语法:-
bleManager.startDeviceScan(
UUIDs: ?Array<UUID>,
options: ?ScanOptions,
listener: (error: ?Error, scannedDevice: ?Device) => void
)https://github.com/Polidea/react-native-ble-plx/wiki/Bluetooth-Scanning
我的代码:-
this.manager.startDeviceScan(null, {allowDuplicates:false}, (error, device) => {
//2nd parameter is scanOptions
if (error) {
// Handle error (scanning will be stopped automatically)
return
}
this.state.count++
if(this.state.count>10)
{
this.manager.stopDeviceScan();
}
console.log("id",device.id)
}请告诉我是否仍然存在语法错误
发布于 2019-07-30 19:42:10
此设置仅适用于iOS,也不会阻止在其中显示重复项。您必须使用集合或等效集合,以确保仅在应用程序中显示/使用唯一的集合
发布于 2021-01-06 19:44:55
我使用包含创建的设备名称的列表,并使用includes()方法检查重复项
refreshScreen(device){
if(!this.state.dataNames.includes(device.name)){
let dataNow = this.state.data;
dataNow.push(element);
let names = this.state.dataNames;
names.push(element.name);
this.setState(
{
refreshing: false,
data: dataNow,
dataNames: names,
}
);
}
}此函数用于添加不在列表dataNames中的设备
https://stackoverflow.com/questions/53882250
复制相似问题