更新记录
1.0.0(2026-09-02)
- 首个版本:iOS 原生 BLE 写入插件
- 绕过 uni 内置蓝牙模块在 iOS 18 上写入无回调的缺陷,直接调用 CoreBluetooth
writeValue:forCharacteristic:type:
- 复用 uni 已建立的系统级连接,通过
retrieveConnectedPeripherals 获取外设,无需重新扫描连接
- 支持 withResponse / withoutResponse 两种写入模式,支持分包发送、3 秒超时保护
平台兼容性
uni-app(5.25)
| Vue2 |
Vue3 |
Chrome |
Safari |
app-vue |
app-nvue |
Android |
iOS |
鸿蒙 |
| × |
× |
× |
× |
√ |
× |
4.4 |
12 |
- |
| 微信小程序 |
支付宝小程序 |
抖音小程序 |
百度小程序 |
快手小程序 |
京东小程序 |
鸿蒙元服务 |
QQ小程序 |
飞书小程序 |
小红书小程序 |
快应用-华为 |
快应用-联盟 |
| × |
× |
× |
× |
× |
× |
× |
× |
× |
× |
× |
× |
uni-app x(5.25)
| Chrome |
Safari |
Android |
iOS |
鸿蒙 |
微信小程序 |
| - |
- |
- |
- |
- |
- |
uts-ble-native-write
iOS 原生 BLE 写入插件。用于绕过 uni-app 内置蓝牙模块在 iOS 18 上 writeBLECharacteristicValue 写入无回调的缺陷。
适用场景
- iOS 18.x 设备上 uni 内置蓝牙写入持续无回调(连接 / notify / 收包正常)
- 已用 LightBlue 等工具确认设备固件支持写入
使用方式
仅 iOS 端生效,Android 端为占位实现(请继续使用 uni 内置写入)。
// #ifdef APP-IOS
import { bleNativeWrite } from '@/uni_modules/uts-ble-native-write/utssdk/index.uts'
// #endif
bleNativeWrite({
deviceId: bleDeviceId, // iOS 端为 peripheral.identifier.uuidString
serviceUuid: 'FFE0',
characteristicUuid: 'FFE1',
hex: 'A5010203...', // 十六进制指令串
writeType: 'writeNoResponse', // 'write' | 'writeNoResponse'
chunkSize: 20 // 分包大小,默认 20
}, (result) => {
if (result.success) {
console.log('写入成功')
} else {
console.log(`写入失败 ${result.code}-${result.message}`)
}
})
回调结果
| code |
含义 |
| 0 |
写入成功 |
| -1 |
上一指令未完成 |
| -2 |
指令数据为空 |
| -3 |
蓝牙未开启 |
| -4 |
未找到已连接设备,请先通过 uni 连接 |
| -5 |
写入超时(蓝牙未回调) |
| -6 |
发现服务失败 |
| -7 |
未找到目标服务 |
| -8 |
发现特征失败 |
| -9 |
未找到目标特征 |
| -10 |
写入失败(系统返回错误) |
| -100 |
Android 平台占位返回 |
注意事项
- 必须使用自定义基座运行,插件不会编译进标准基座
- 写入前请确保 uni 蓝牙连接已建立(连接仍由 uni 内置模块负责)
- withoutResponse 模式无系统回调,按 50ms 间隔分包发送