在iOS上通过BTLE发送数据时的最大数据大小

Bla*_*olf 11 data-transfer objective-c ios core-bluetooth bluetooth-lowenergy

我目前正在实现一个iOS应用程序,它使用CoreBluetooth在两个设备之间传输数据.例如,要将数据从中央发送到外设,我使用以下代码:

NSData *data = [NSJSONSerialization dataWithJSONObject:dictionary options:NSJSONWritingPrettyPrinted error:nil];
NSLog(@"Writing data of length %d", [data length]);
[peripheral writeValue:data forCharacteristic:characteristic type:CBCharacteristicWriteWithResponse];
Run Code Online (Sandbox Code Playgroud)

这个工作绝对正常,但问题是我已经多次读过,因为特性一次最多可以传输20个字节.此外,当我查看Apple的BTLE示例代码时, 他们实现了一种将数据拆分为20字节块的机制.但是上面的代码打印出类似Writing data of length 124的东西- 数据在其他设备上很好地到达.

那么:为什么这个工作呢?更重要的是,我担心这会在某些时候破裂,特别是当非iOS设备发挥作用时.

Oli*_*ork 2

我使用的是 iOS 7.1.1,并且还发现我可以使用 BLE 将多达 132 字节的数据从 iPhone 可靠地发送到 iPad。我还听说 20 字节是最大值,但看起来确实不是这样