wx.getBLEDeviceServices出现10004的错误码
发布于 6 年前 作者 ping09 8838 次浏览 来自 问答
  • 当前 Bug 的表现(可附上截图)
  • 预期表现
  • 复现路径
  • 提供一个最简复现 Demo

//点击连接蓝牙

connectBlueTooth: function (item) {

let that = this

// wx.showLoading({

//   title: ‘连接中…’

// })

console.debug(“连接蓝牙”, item)

that.data.blueToothTtem = item

// console.debug(“连接蓝牙”, item.currentTarget.dataset.item.deviceId)

wx.createBLEConnection({

// 这里的 deviceId 需要已经通过 createBLEConnection 与对应设备建立链接

deviceId: item.deviceId,

timeout: 30000,

success: function (res) {

console.debug(‘连接蓝牙成功—’, res)

// wx.hideLoading()

that.data.times = 1

setTimeout(() => {

that.getBlueToothService()

}, 1500)

},

fail: function (res) {

app.globalData.isOrderConnect = true

console.debug(‘连接失败’, res)

console.log(‘serviceTimes次数:’, that.data.serviceTimes)

if(that.data.serviceTimes < 4){

that.data.serviceTimes++

if(that.data.serviceTimes === 3){

console.log(‘连接失败次数’)

wx.showToast({

title: ‘连接失败’,

complete:function(){

that.data.isConnectedBlueTooth = false;

//跳转下一个页面

setTimeout(() => {

that.data.serviceTimes = 1

wx.hideToast()

//跳转下一个页面

that.jumpToNextPage()

}, 1000)

}

})

} else {

//重新搜索

setTimeout(() => {

console.debug(‘再次连接失败’)

that.data.serviceTimes = 1

that.searchBlueTooth()

}, 2000)

}

}

if (that.data.serviceTimes >= 4){

wx.showToast({

title: ‘连接失败’,

complete: function (){

that.data.isConnectedBlueTooth = false;

//跳转下一个页面

setTimeout(() => {

that.data.serviceTimes = 1

wx.hideToast()

//跳转下一个页面

that.jumpToNextPage()

}, 1000)

}

})

}

}

})

},

getBlueToothService: function () {

var that = this;

//this.data.deviceId

let deviceId = that.data.blueToothTtem.deviceId

wx.getBLEDeviceServices({

deviceId: deviceId,

success: function (res) {

console.debug(‘获取蓝牙设备的所有服务:’, JSON.stringify(res.services));

app.globalData.services = res.services

that.data.times = 1

//连接蓝牙成功

that.data.isConnectedBlueTooth = true;

//跳转下一个页面

setTimeout(() => {

wx.hideToast()

//跳转下一个页面

that.jumpToNextPage()

}, 500)

},

fail: function (error) {

//不成功之后的次数

console.debug(‘重新找服务类型:’, that.data.isConnectting)

if (that.data.isConnectting) {

that.data.serviceTimes++

console.debug(‘重新找服务’)

if (that.data.serviceTimes < 5) {

//重新找服务

if (that.data.serviceTimes === 2) {

setTimeout(() => {

app.globalData.deviceID = ‘’

that.data.serviceError = true

//释放资源重新来

that.closeBlueTooth()

}, 1500)

} else if (that.data.serviceTimes === 3) {

setTimeout(() => {

app.globalData.deviceID = ‘’

that.data.serviceError = true

//释放资源重新来

that.closeBlueTooth()

}, 2000)

} else {

setTimeout(() => {

app.globalData.deviceID = ‘’

that.data.serviceError = true

//释放资源重新来

that.closeBlueTooth()

}, 3000)

}

}

} else {

console.debug(‘重新连接’)

that.data.serviceTimes++

if (that.data.serviceTimes < 5) {

//重新连接

setTimeout(() => {

that.connectBlueTooth(that.data.blueToothTtem)

}, 2000)

}

}

if (that.data.serviceTimes === 5) {

console.log(‘服务的次数:’, that.data.serviceTimes)

that.data.serviceTimes = 1

that.data.times = 1

wx.showToast({

title: ‘连接失败’,

icon: ‘none’,

complete: function () {

//跳转下一个页面

setTimeout(() => {

wx.hideToast()

//跳转下一个页面

that.jumpToNextPage()

}, 1000)

}

})

}

console.debug(‘所有服务error:’, error)

}

})

},

手机:Redmi Note 4x ,MIUI版本:MIUI 10.2.

日志上传时间:5月15号 09:38

微信号是:OnlyOne_0451

问题描述: 第一次出现了找不到服务,然后再重新来一遍(释放蓝牙资源程序,重新连接,查找服务),连续二次还是不行,请问是什么原因

回到顶部