gpt4 book ai didi

android - 使用 react-native-ble-plx 避免重复的 BLE 设备

转载 作者:行者123 更新时间:2023-11-29 02:23:13 53 4
gpt4 key购买 nike

我正在使用 react-native-ble-plx 在我的应用程序中实现蓝牙

蓝牙扫描工作正常,但它在 android 中包含重复项,而在 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)
}

请告知是否仍然存在任何语法错误

最佳答案

此设置仅适用于 iOS,也不会阻止在那里显示重复项。您必须使用集合或等效物来确保在您的应用中只显示/使用唯一的

关于android - 使用 react-native-ble-plx 避免重复的 BLE 设备,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53882250/

53 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com