start() {
let that = this
uni.openBluetoothAdapter({
success(res) {
console.log('初始化成功');
that.find()
},
fail(res) {
that.statu = false
console.error(res, '初始化失败');
if (res.code == 10001) {
that.title = that.$t('index.findError')
that.info = that.$t('index.error')
}
}
})
},
// 搜寻附近蓝牙
find() {
let that = this
uni.startBluetoothDevicesDiscovery({
services: ['FEE7'],
success(res) {
console.log(res);
that.getDervices()
},
fail(e) {
that.statu = false;
console.error('搜寻失败', e);
}
})
},
// 获得设备列表
getDervices() {
let that = this
console.log('进入回调');
uni.onBluetoothDeviceFound(function(res) {
console.log(res);
that.list.push(res.devices[0])
})
},
// 停止匹配
stopFind() {
uni.stopBluetoothDevicesDiscovery({
success(res) {
console.log('停止搜寻', res)
}
})
}
```**
- 发布:2024-06-05 18:17
- 更新:2024-06-19 20:22
- 阅读:202
产品分类: uniapp/App
PC开发环境操作系统: Windows
PC开发环境操作系统版本号: 10
HBuilderX类型: 正式
HBuilderX版本号: 4.15
手机系统: iOS
手机系统版本号: iOS 13.0
手机厂商: 苹果
手机机型: ios 13
页面类型: vue
vue版本: vue2
打包方式: 云端
项目创建方式: HBuilderX
示例代码:
操作步骤:
start() {
let that = this
uni.openBluetoothAdapter({
success(res) {
console.log('初始化成功');
that.find()
},
fail(res) {
that.statu = false
console.error(res, '初始化失败');
if (res.code == 10001) {
that.title = that.$t('index.findError')
that.info = that.$t('index.error')
}
}
})
},
// 搜寻附近蓝牙
find() {
let that = this
uni.startBluetoothDevicesDiscovery({
services: ['FEE7'],
success(res) {
console.log(res);
that.getDervices()
},
fail(e) {
that.statu = false;
console.error('搜寻失败', e);
}
})
},
// 获得设备列表
getDervices() {
let that = this
console.log('进入回调');
uni.onBluetoothDeviceFound(function(res) {
console.log(res);
that.list.push(res.devices[0])
})
},
// 停止匹配
stopFind() {
uni.stopBluetoothDevicesDiscovery({
success(res) {
console.log('停止搜寻', res)
}
})
}
```**
start() {
let that = this
uni.openBluetoothAdapter({
success(res) {
console.log('初始化成功');
that.find()
},
fail(res) {
that.statu = false
console.error(res, '初始化失败');
if (res.code == 10001) {
that.title = that.$t('index.findError')
that.info = that.$t('index.error')
}
}
})
},
// 搜寻附近蓝牙
find() {
let that = this
uni.startBluetoothDevicesDiscovery({
services: ['FEE7'],
success(res) {
console.log(res);
that.getDervices()
},
fail(e) {
that.statu = false;
console.error('搜寻失败', e);
}
})
},
// 获得设备列表
getDervices() {
let that = this
console.log('进入回调');
uni.onBluetoothDeviceFound(function(res) {
console.log(res);
that.list.push(res.devices[0])
})
},
// 停止匹配
stopFind() {
uni.stopBluetoothDevicesDiscovery({
success(res) {
console.log('停止搜寻', res)
}
})
}
```**
预期结果:
uni.onBluetoothDeviceFound正常返回
uni.onBluetoothDeviceFound正常返回
实际结果:
uni.onBluetoothDeviceFound无响应
uni.onBluetoothDeviceFound无响应
bug描述:
打包后蓝牙搜索除了安卓和苹果15,苹果15以下所有机型全部搜索不到蓝牙,真机测试发现原因是uni.onBluetoothDeviceFound不触发导致,望官方解决