uni-app ios蓝牙发送数据配置writeType=writeNoResponse无效
uni-app ios蓝牙发送数据配置writeType=writeNoResponse无效
| 项目信息 | 详情 |
|---|---|
| 产品分类 | uniapp/App |
| PC开发环境 | Mac |
| PC操作系统版本 | 14.1.2 (23B92) |
| HBuilderX类型 | 正式 |
| HBuilderX版本 | 3.98 |
| 手机系统 | iOS |
| 手机系统版本 | iOS 17 |
| 手机厂商 | 苹果 |
| 手机机型 | iphone13 |
| 页面类型 | vue |
| vue版本 | vue2 |
| 打包方式 | 云端 |
| 项目创建方式 | HBuilderX |
示例代码:
async writeCharacteristic(deviceId, serviceUuid, characteristicUuid, data) {
console.log('writeCharacteristic ---->> 开始发送数据...')
return new Promise((resolve, reject) => {
uni.writeBLECharacteristicValue({
deviceId: deviceId,
serviceId: serviceUuid,
characteristicId: characteristicUuid,
value: data,
writeType: 'writeNoResponse',
success: (res) => {
console.log(deviceId + "数据发送成功~")
resolve(res);
},
fail: (error) => {
console.log(deviceId + "数据发送失败~:" + data, error)
reject(error);
}
});
});
}
操作步骤:
必现,所有苹果手机都一样的
预期结果:
秒级发送
实际结果:
3-4秒才发送成功
bug描述:
如附件所示:
ios端配置了writeType: 'writeNoResponse’没有生效每发送一次蓝牙指令时间在3-4秒。

更多关于uni-app ios蓝牙发送数据配置writeType=writeNoResponse无效的实战教程也可以访问 https://www.itying.com/category-93-b0.html
更多关于uni-app ios蓝牙发送数据配置writeType=writeNoResponse无效的实战教程也可以访问 https://www.itying.com/category-93-b0.html
在使用 uni-app 开发 iOS 应用时,如果你在蓝牙通信中设置了 writeType 为 writeNoResponse,但发现该配置无效,可能是因为 iOS 系统对蓝牙通信的处理方式与 Android 不同。以下是一些可能的原因和解决方案:
1. iOS 系统的限制
iOS 系统对蓝牙通信的处理方式与 Android 有所不同。在 iOS 中,writeNoResponse 并不总是被支持,尤其是在某些蓝牙设备或服务中。iOS 系统可能会自动将 writeNoResponse 转换为 writeWithResponse,以确保数据的可靠传输。
2. 检查蓝牙设备的特性
确保你正在写入的蓝牙特性(Characteristic)支持 writeNoResponse。你可以通过检查特性的 properties 属性来确认。如果特性不支持 writeNoResponse,那么即使你在代码中设置了 writeType,iOS 系统也会忽略该设置。
3. 使用 writeWithResponse
如果 writeNoResponse 无效,你可以尝试使用 writeWithResponse。虽然这可能会增加一些延迟,但它可以确保数据被成功写入到蓝牙设备。
uni.writeBLECharacteristicValue({
deviceId: deviceId,
serviceId: serviceId,
characteristicId: characteristicId,
value: value,
writeType: 'writeWithResponse', // 使用 writeWithResponse
success: (res) => {
console.log('写入成功', res);
},
fail: (err) => {
console.log('写入失败', err);
}
});

