5***@qq.com
5***@qq.com
  • 发布:2023-12-15 18:02
  • 更新:2023-12-18 17:42
  • 阅读:287

【报Bug】ios无法获取蓝牙的serviceData

分类:uni-app

产品分类: uniapp/App

PC开发环境操作系统: Windows

PC开发环境操作系统版本号: Windows 11 专业版

HBuilderX类型: 正式

HBuilderX版本号: 3.8.12

手机系统: iOS

手机系统版本号: iOS 16

手机厂商: 苹果

手机机型: IPhone13

页面类型: vue

vue版本: vue3

打包方式: 云端

项目创建方式: HBuilderX

示例代码:

//蓝牙识别
configBlueTooth() {
let _this = this
this.getBluetoothAdapterState().then(res => {
if (res === 'ok') {
//开启设备搜索
this.startBluetoothDevicesDiscovery().then(res1 => {
if (res1 === 'ok') {
this.getBluetooth()
}
})
}else {
//开启蓝牙模块
_this.openBluetoothAdapter().then(res2 => {
if (res2 === 'ok') {
//开启设备搜索
this.startBluetoothDevicesDiscovery().then(res1 => {
if (res1 === 'ok') {
this.getBluetooth()
}
})
}else {
// console.log('蓝牙初始化失败')
}
})
}
})
},

//获取蓝牙设备
getBluetooth() {
let _this = this
//监听寻找到新设备的事件
uni.onBluetoothDeviceFound(function (devices) {
if(devices.devices[0].name){
_this.blueTooth.push(devices.devices[0])
console.log(_this.blueTooth)
}
})
},

async openBluetoothAdapter(){
let _this = this
let result = new Promise( (resolve, reject) => {
uni.openBluetoothAdapter({
success(res) {
resolve('ok')
},
fail(res) {
resolve(res)
},
})
})
return result
},
async getBluetoothAdapterState(){
let _this = this
let result = new Promise( (resolve, reject) => {
uni.getBluetoothAdapterState({
success(res) {
resolve('ok')
},
fail(res) {
resolve(res)
},
})
})
return result
},

async startBluetoothDevicesDiscovery(){
let _this = this
let result = new Promise( (resolve, reject) => {
uni.startBluetoothDevicesDiscovery({
success(res) {
resolve('ok')
},
fail(res) {
resolve(res)
},
})
})
return result
},

操作步骤:

先打开手机蓝牙再试

预期结果:

IOS能打印出serviceData

实际结果:

IOS无法打印出serviceData

bug描述:

打印 _this.blueTooth ,安卓有serviceData,IOS没有serviceData,但是蓝牙的mac地址储存在serviceData,无法稳定获取serviceData

安卓:
{
"deviceId": "52:01:23:11:00:31",
"name": "R23110049",
"RSSI": -53,
"localName": "R23110049",
"advertisServiceUUIDs": [],
"advertisData": {},
"serviceData": {
"00001803-0000-1000-8000-00805F9B34FB": {}
}
},

IOS:
{
"RSSI": -57,
"advertisData": "",
"deviceId": "AA11EF7D-B662-84A6-BA0B-8828F436AC5D",
"name": "R23110049"
},

2023-12-15 18:02 负责人:无 分享
已邀请:
DCloud_iOS_WZT

DCloud_iOS_WZT

提供一个示例吧

DCloud_iOS_WZT

DCloud_iOS_WZT

startBluetoothDevicesDiscovery 允许重复获取试一下

  • 5***@qq.com (作者)

    可以了,谢谢

    2023-12-19 09:27

  • Azikou

    回复 5***@qq.com: 咋整的,指教下,我也不行,就正常的获取广播信息,然后拿不到serviceData

    2024-01-05 10:43

  • 9***@qq.com

    回复 Azikou: 你好你解决这个问题了吗?我这ios也拿不到serviceData

    2024-05-10 14:57

要回复问题请先登录注册