【发布时间】:2021-06-11 01:12:45
【问题描述】:
我正在构建一个网络应用程序(在移动浏览器上运行,而不是移动应用程序),目的是能够检测附近的蓝牙设备,以便用户可以打卡/打卡以参加他们的出勤。
我有一个工作代码https://stackblitz.com/edit/bluetooth-3ibcww 并且必须在https://bluetooth-3ibcww.stackblitz.io/ 中运行以避免CROS 错误。 有没有办法避免“提示”?我需要模拟用户点击“注册考勤”按钮的流程,后端将扫描附近的蓝牙设备并识别特定的“ATTENDANCE_DETECTOR”蓝牙,以证明工作人员在办公室/工厂附近。 这是工作代码
let options = {
acceptAllDevices: true,
optionalServices: ["battery_service"]
};
navigator.bluetooth
.requestDevice(options)
.then(function(device) {
console.log("Name: " + device.name);
// Do something with the device.
})
.catch(function(error) {
console.log("Something went wrong. " + error);
});
我查看了官方文档https://developer.mozilla.org/en-US/docs/Web/API/Bluetooth 似乎只有一种可用的方法 requestDevice()
【问题讨论】:
标签: angular typescript bluetooth web-bluetooth