IOS启动蓝牙监听,写入数据报错。但是设备能正常接收。
错误如下:
send-error-{"errMsg":"writeBLECharacteristicValue:fail Error Domain=CBATTErrorDomain Code=14 \"Unlikely error.\" UserInfo={NSLocalizedDescription=Unlikely error.},https://ask.dcloud.net.cn/article/282","errCode":10007,"code":10007}
接收到的数据打印如下:
value-succ{"characteristicId":"0000FFE1-0000-1000-8000-00805F9B34FB","deviceId":"78E496C9-3688-8D6C-B60D-B17D69A597C1","serviceId":"0000FFE0-0000-1000-8000-00805F9B34FB","value":{}}
value 是空的,但是确实每次都监听到了。
实现代码如下。
await uni.notifyBLECharacteristicValueChange({
state: true, // 启用 notify 功能
deviceId,
serviceId,
characteristicId,
success: res => {
console.log('notify-succ:' + JSON.stringify(res));
that.iGlobal.uploadlog('notify-succ'+JSON.stringify(res))
uni.onBLECharacteristicValueChange((res2) => {
console.log('value-succ:' + JSON.stringify(res2));
that.iGlobal.uploadlog('value-succ'+JSON.stringify(res2))
});
},
fail: err => {
console.log('notify-failed:' + JSON.stringify(err));
that.iGlobal.uploadlog('notify-failed'+JSON.stringify(err))
}
});
写入代码如下。
that.iBluetooth.writeBLECharacteristicValue(encoded)
.then(res => {
that.iGlobal.uploadlog('woshou-'+JSON.stringify(res))
that.iGlobal.addCache('selectBlueTooth',that.iBluetooth,30 * 36000);
//跳入操作页面
setTimeout(() => {
that.iGlobal.togo2('../../pages/index/index')
},200);
})
.catch(error => {
that.iGlobal.uploadlog('woshou-'+JSON.stringify(error))
that.iGlobal.addCache('selectBlueTooth',that.iBluetooth,30 * 36000);
//跳入操作页面
setTimeout(() => {
that.iGlobal.togo2('../../pages/index/index')
},200);
//this.iGlobal.showToast('握手失败');
});
0 个回复