当我通过调用方法startDevcieScan()开始设备扫描时,大多数时候会出现“不支持蓝牙”警报。这仅在ios中发生。我无法弄清楚为什么会这样。我在iphone 5s,6s和ipad等实际设备上测试了该代码。
下面是代码段:
let that = this;
let deviceList = [];
let count = 0;
that.manager.startDeviceScan(["1802"], null, (error, device) => {
if (error) {
try {
alert(`${error.message}`);
Log.info(`BLE scan error: ${error.message}`);
} catch (e) {
Log.info(`BLE scan error: ${error}`);
}
return;
}
let localDeviceList = deviceList;
let exists = false;
localDeviceList.map((d) => {
if (d.id == device.id) {
exists = true;
}
});
if (!exists) {
deviceList.push(device);
this.homeScreen.setState({listBLEDevices: deviceList});
let arr = this.homeScreen.state.availableDevices;
arr.push({id: device.id, name: device.name, connected: false});
this.homeScreen.setState({availableDevices: arr});
}
});
};