iOS 写入数据超过200字节报错 文章目录 iOS 写入数据超过200字节报错官方建议:报错问题解决 writeblecharacteristicvalue 官方建议: 并行调用多次会存在写失败的可能性。APP不会对写入数据包大小做限制,但系统与蓝牙设备会限制蓝牙4.0单次传输的数据大小,超过最大字节数后会发生写入错误,建议每次写入不超过20字节。若单次写入数据过长,iOS 上存在系统不会有任何回调的情况(包括错误回调)。安卓平台上,在调用 notifyBLECharacteristicValueChange 成功后立即调用 writeBLECharacteristicValue 接口,在部分机型上会发生 10008 系统错误 报错问题 iPhone 6:写入数据超过200字节时,报错当前特征值不支持此操作,写入失败;iPhone 11、iPhone 12等,能正常写入数据,其他机型没有细测; { "errMsg": "writeBLECharacteristicValue:fail Error Domain=CBATTErrorDomain Code=17 \"Resources are insufficient.\" UserInfo={NSLocalizedDescription=Resources are insufficient.},https://ask.dcloud.net.cn/article/282", "errCode": 10007, "code": 10007 } 解决 经测试,iPhone6 写入数据不超过160字节时,写入成功,正常通信;仅供参考 const writeBLECharacteristicValue = (hex) => { let buffer = hexToArrayBuffer(hex); // 16进制转ArrayBuffer,之前有分享过 uni.writeBLECharacteristicValue({ deviceId, serviceId, characteristicId, value: buffer, success(res) { console.log('writeBLECharacteristicValue success', res.errMsg) } }) }