What does [peripheral maximumWriteValueLengthForType:CBCharacteristicWriteWithResponse] return?

不想你离开。 提交于 2019-12-11 07:13:37

问题


I am running the following code:

[peripheral maximumWriteValueLengthForType:CBCharacteristicWriteWithResponse];

In my case (iPhone 7, iOS 10.0.2) it returns 512. What is the meaning of this number?

From documentation:

method maximumWriteValueLengthForType:

The maximum amount of data, in bytes, that can be sent to a characteristic in a single write type.

But if I try to send 500 or 600 bytes it works absolutely the same. The target device receives all data. And in both cases response callback is not called.


回答1:


As I understand, in theory it should return the ATT MTU size, as it was requested from the central to the peripheral. From the peripheral side, similar value is central.maximumUpdateValueLength and it is suggested to avoid sending notifications with characteristic values larger than central.maximumUpdateValueLength. But unfortunately this is not clearly documented and also Apple's own example (BTETransfer app) is using default ATT MTU size of 20 to be safe. For notifications, I assume, bad things might happen if you attempt to change more than central.maximumUpdateValueLength bytes.

But from my experiments on Android, I found out that from the other side - central side - some kind of caching is going on and it is possible to send more bytes than the current ATT MTU size (on Android, it is available through onMtuChanged and seems to also be negotiated to 512 immediately after connection). So, we might assume that on iOS the same kind of caching is going on, but I'm not sure how large it can go. On Android, we at least have write callbacks to know when it is safe to write more data. On iOS, not sure what would happen if we try to write, let's say 1MB on a writable characteristic from the central side. But I will try it today.

Also, the behavior might differ among iOS versions because central.maximumUpdateValueLength is available since iOS 7 but peripheral maximumWriteValueLengthForType only since iOS 9.



来源:https://stackoverflow.com/questions/41289783/what-does-peripheral-maximumwritevaluelengthfortypecbcharacteristicwritewithre

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!