[iOS][BLE] Get negotiate MTU

烂漫一生 提交于 2019-12-10 10:15:06

问题


I'm currently developing a BLE App in iOS. In my application I need to implement a segmentation protocol to send large datas using BLE. My application need to have the Central role.

My issue is that I can't get the negotiate MTU. I can get the maximumWriteValueLength of my peripheral but it is bigger that mine and can't find the maximumWriteValueLength of my central object.

Did someone know a way to find the negotiate MTU or a way to access the CBCentral object of my CBCentralManager?


回答1:


iOS kicks off an MTU exchange automatically upon connection.

Devices running iOS < 10 will request an MTU size of 158. Newer devices running iOS 10 will request an MTU size of 185.

Assuming the device you are connected to supports these sizes, that is what you should see.

You should be able to determine the max payload size negotiated by looking at the maximumUpdateValueLength property of the CBCentral. (Note this will be 3 bytes less than the ATT MTU since that's the overhead for a ATT notification/indication)




回答2:


I don't know if you are looking for this. but in my case I ask to the peripheral sending this message:

print("Max write value: \(peripheral.maximumWriteValueLength(for: .withResponse))")



回答3:


I will answer for people with same issue.

Right now (February 2017) the MTU of iPhone in Peripheral role is always 158. So what I have found in short solution (just to make some test) is to compare the Central MTU to 158 and take the smaller one. For a solution more stable peripheral will write the MTU size inside a specific characteristic that I will read after the connection.



来源:https://stackoverflow.com/questions/41977767/iosble-get-negotiate-mtu

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